In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
In [2]:
import os
In [3]:
dir(os)
Out[3]:
['CLD_CONTINUED',
 'CLD_DUMPED',
 'CLD_EXITED',
 'CLD_TRAPPED',
 'DirEntry',
 'EX_CANTCREAT',
 'EX_CONFIG',
 'EX_DATAERR',
 'EX_IOERR',
 'EX_NOHOST',
 'EX_NOINPUT',
 'EX_NOPERM',
 'EX_NOUSER',
 'EX_OK',
 'EX_OSERR',
 'EX_OSFILE',
 'EX_PROTOCOL',
 'EX_SOFTWARE',
 'EX_TEMPFAIL',
 'EX_UNAVAILABLE',
 'EX_USAGE',
 'F_LOCK',
 'F_OK',
 'F_TEST',
 'F_TLOCK',
 'F_ULOCK',
 'MutableMapping',
 'NGROUPS_MAX',
 'O_ACCMODE',
 'O_APPEND',
 'O_ASYNC',
 'O_CLOEXEC',
 'O_CREAT',
 'O_DIRECT',
 'O_DIRECTORY',
 'O_DSYNC',
 'O_EXCL',
 'O_LARGEFILE',
 'O_NDELAY',
 'O_NOATIME',
 'O_NOCTTY',
 'O_NOFOLLOW',
 'O_NONBLOCK',
 'O_RDONLY',
 'O_RDWR',
 'O_RSYNC',
 'O_SYNC',
 'O_TRUNC',
 'O_WRONLY',
 'POSIX_FADV_DONTNEED',
 'POSIX_FADV_NOREUSE',
 'POSIX_FADV_NORMAL',
 'POSIX_FADV_RANDOM',
 'POSIX_FADV_SEQUENTIAL',
 'POSIX_FADV_WILLNEED',
 'PRIO_PGRP',
 'PRIO_PROCESS',
 'PRIO_USER',
 'P_ALL',
 'P_NOWAIT',
 'P_NOWAITO',
 'P_PGID',
 'P_PID',
 'P_WAIT',
 'PathLike',
 'RTLD_DEEPBIND',
 'RTLD_GLOBAL',
 'RTLD_LAZY',
 'RTLD_LOCAL',
 'RTLD_NODELETE',
 'RTLD_NOLOAD',
 'RTLD_NOW',
 'R_OK',
 'SCHED_BATCH',
 'SCHED_FIFO',
 'SCHED_IDLE',
 'SCHED_OTHER',
 'SCHED_RESET_ON_FORK',
 'SCHED_RR',
 'SEEK_CUR',
 'SEEK_END',
 'SEEK_SET',
 'ST_APPEND',
 'ST_MANDLOCK',
 'ST_NOATIME',
 'ST_NODEV',
 'ST_NODIRATIME',
 'ST_NOEXEC',
 'ST_NOSUID',
 'ST_RDONLY',
 'ST_RELATIME',
 'ST_SYNCHRONOUS',
 'ST_WRITE',
 'TMP_MAX',
 'WCONTINUED',
 'WCOREDUMP',
 'WEXITED',
 'WEXITSTATUS',
 'WIFCONTINUED',
 'WIFEXITED',
 'WIFSIGNALED',
 'WIFSTOPPED',
 'WNOHANG',
 'WNOWAIT',
 'WSTOPPED',
 'WSTOPSIG',
 'WTERMSIG',
 'WUNTRACED',
 'W_OK',
 'XATTR_CREATE',
 'XATTR_REPLACE',
 'XATTR_SIZE_MAX',
 'X_OK',
 '_Environ',
 '__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 '_execvpe',
 '_exists',
 '_exit',
 '_fspath',
 '_fwalk',
 '_get_exports_list',
 '_putenv',
 '_spawnvef',
 '_unsetenv',
 '_wrap_close',
 'abc',
 'abort',
 'access',
 'altsep',
 'chdir',
 'chmod',
 'chown',
 'chroot',
 'close',
 'closerange',
 'confstr',
 'confstr_names',
 'cpu_count',
 'ctermid',
 'curdir',
 'defpath',
 'device_encoding',
 'devnull',
 'dup',
 'dup2',
 'environ',
 'environb',
 'error',
 'execl',
 'execle',
 'execlp',
 'execlpe',
 'execv',
 'execve',
 'execvp',
 'execvpe',
 'extsep',
 'fchdir',
 'fchmod',
 'fchown',
 'fdatasync',
 'fdopen',
 'fork',
 'forkpty',
 'fpathconf',
 'fsdecode',
 'fsencode',
 'fspath',
 'fstat',
 'fstatvfs',
 'fsync',
 'ftruncate',
 'fwalk',
 'get_blocking',
 'get_exec_path',
 'get_inheritable',
 'get_terminal_size',
 'getcwd',
 'getcwdb',
 'getegid',
 'getenv',
 'getenvb',
 'geteuid',
 'getgid',
 'getgrouplist',
 'getgroups',
 'getloadavg',
 'getlogin',
 'getpgid',
 'getpgrp',
 'getpid',
 'getppid',
 'getpriority',
 'getresgid',
 'getresuid',
 'getsid',
 'getuid',
 'getxattr',
 'initgroups',
 'isatty',
 'kill',
 'killpg',
 'lchown',
 'linesep',
 'link',
 'listdir',
 'listxattr',
 'lockf',
 'lseek',
 'lstat',
 'major',
 'makedev',
 'makedirs',
 'minor',
 'mkdir',
 'mkfifo',
 'mknod',
 'name',
 'nice',
 'open',
 'openpty',
 'pardir',
 'path',
 'pathconf',
 'pathconf_names',
 'pathsep',
 'pipe',
 'pipe2',
 'popen',
 'posix_fadvise',
 'posix_fallocate',
 'pread',
 'preadv',
 'putenv',
 'pwrite',
 'pwritev',
 'read',
 'readlink',
 'readv',
 'register_at_fork',
 'remove',
 'removedirs',
 'removexattr',
 'rename',
 'renames',
 'replace',
 'rmdir',
 'scandir',
 'sched_get_priority_max',
 'sched_get_priority_min',
 'sched_getaffinity',
 'sched_getparam',
 'sched_getscheduler',
 'sched_param',
 'sched_rr_get_interval',
 'sched_setaffinity',
 'sched_setparam',
 'sched_setscheduler',
 'sched_yield',
 'sendfile',
 'sep',
 'set_blocking',
 'set_inheritable',
 'setegid',
 'seteuid',
 'setgid',
 'setgroups',
 'setpgid',
 'setpgrp',
 'setpriority',
 'setregid',
 'setresgid',
 'setresuid',
 'setreuid',
 'setsid',
 'setuid',
 'setxattr',
 'spawnl',
 'spawnle',
 'spawnlp',
 'spawnlpe',
 'spawnv',
 'spawnve',
 'spawnvp',
 'spawnvpe',
 'st',
 'stat',
 'stat_result',
 'statvfs',
 'statvfs_result',
 'strerror',
 'supports_bytes_environ',
 'supports_dir_fd',
 'supports_effective_ids',
 'supports_fd',
 'supports_follow_symlinks',
 'symlink',
 'sync',
 'sys',
 'sysconf',
 'sysconf_names',
 'system',
 'tcgetpgrp',
 'tcsetpgrp',
 'terminal_size',
 'times',
 'times_result',
 'truncate',
 'ttyname',
 'umask',
 'uname',
 'uname_result',
 'unlink',
 'unsetenv',
 'urandom',
 'utime',
 'wait',
 'wait3',
 'wait4',
 'waitid',
 'waitid_result',
 'waitpid',
 'walk',
 'write',
 'writev']
In [4]:
os.listdir()
Out[4]:
['.ipynb_checkpoints',
 '20.10.19',
 'freddi.dat',
 'diagram.csv',
 'cat.jpg',
 'V404Cyg.txt.gz',
 'Untitled.html',
 'io.html',
 'test.fits',
 'tmp.dat',
 'cat.txt',
 'cat.npy',
 'cat.npz',
 'io1.ipynb']
In [5]:
os.listdir('20.10.19')
Out[5]:
['mymodule.py',
 'myscript.py',
 'numpy-submodules.html',
 'numpy-submodules.ipynb',
 'other_script.py']
In [6]:
for root, dirs, files in os.walk('.'):
    print(root, dirs, files)
. ['.ipynb_checkpoints', '20.10.19'] ['freddi.dat', 'diagram.csv', 'cat.jpg', 'V404Cyg.txt.gz', 'Untitled.html', 'io.html', 'test.fits', 'tmp.dat', 'cat.txt', 'cat.npy', 'cat.npz', 'io1.ipynb']
./.ipynb_checkpoints [] ['numpy-submodules-checkpoint.ipynb', 'io1-checkpoint.ipynb']
./20.10.19 [] ['mymodule.py', 'myscript.py', 'numpy-submodules.html', 'numpy-submodules.ipynb', 'other_script.py']
In [7]:
os.path
Out[7]:
<module 'posixpath' from '/opt/conda/lib/python3.7/posixpath.py'>
In [8]:
import pathlib
In [9]:
d = '20.10.19'
fname = 'other_script.py'
os.path.join(d, fname)
Out[9]:
'20.10.19/other_script.py'
In [10]:
# ПЛОХО
d + '/' + fname
Out[10]:
'20.10.19/other_script.py'
In [11]:
dir(os.path)
Out[11]:
['__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 '_get_sep',
 '_joinrealpath',
 '_varprog',
 '_varprogb',
 'abspath',
 'altsep',
 'basename',
 'commonpath',
 'commonprefix',
 'curdir',
 'defpath',
 'devnull',
 'dirname',
 'exists',
 'expanduser',
 'expandvars',
 'extsep',
 'genericpath',
 'getatime',
 'getctime',
 'getmtime',
 'getsize',
 'isabs',
 'isdir',
 'isfile',
 'islink',
 'ismount',
 'join',
 'lexists',
 'normcase',
 'normpath',
 'os',
 'pardir',
 'pathsep',
 'realpath',
 'relpath',
 'samefile',
 'sameopenfile',
 'samestat',
 'sep',
 'split',
 'splitdrive',
 'splitext',
 'stat',
 'supports_unicode_filenames',
 'sys']
In [12]:
os.path.exists(os.path.join(d, fname))
Out[12]:
True
In [13]:
?os.removedirs
In [14]:
import shutil
In [15]:
?shutil.rmtree
In [16]:
shutil.copy
Out[16]:
<function shutil.copy(src, dst, *, follow_symlinks=True)>
In [17]:
shutil.move
Out[17]:
<function shutil.move(src, dst, copy_function=<function copy2 at 0x7fd1dddb1680>)>
In [18]:
!ls
20.10.19  cat.npz      freddi.dat  test.fits	  V404Cyg.txt.gz
cat.jpg   cat.txt      io1.ipynb   tmp.dat
cat.npy   diagram.csv  io.html	   Untitled.html
In [19]:
fd = open('diagram.csv')
text = fd.read()
fd.close()
In [20]:
print(text[:100])
0.036950897,-19.812012
0.03500012,32.59825
0.2093362,42.75399
0.25276598,9.813249
0.2743527,-36.1325
In [21]:
# НЕПИТОНОВО

def read_file(file_path):
    try:
        fd = open(file_path)
        text = fd.read()
        x = text[100]
        raise RuntimeError('ERROR')
    # except RuntimeError as e:
    #     print(e)
    #     raise ValueError('Value Error') from e
    finally:
        fd.close()
    return text
In [22]:
with open('diagram.csv') as fd:
    text = fd.read()
fd.closed
Out[22]:
True
In [23]:
import contextlib
In [24]:
from astropy.io import fits
In [25]:
with fits.open('test.fits', mode='ostream') as f:
    pass
In [26]:
# Учебный пример

def parse_csv(file_path):
    x = []
    y = []
    with open(file_path) as fd:
        for line in fd:
            line = line.strip()
            x_, y_ = map(float, line.split(','))
            x.append(x_)
            y.append(y_)
    return x, y


x, y = parse_csv('diagram.csv')
plt.plot(x, y, 'x')
print(x)
[0.036950897, 0.03500012, 0.2093362, 0.25276598, 0.2743527, 0.27199373, 0.44834232, 0.50287396, 0.49865913, 0.6310321, 0.90020174, 0.9007238, 0.8012198, 0.89946604, 0.89804685, 1.0035977, 1.100515, 1.1055652, 1.3991741, 1.699523, 2.0069914, 1.9971569, 2.0035028, 1.9957709]
In [27]:
!head -n2 diagram.csv
0.036950897,-19.812012
0.03500012,32.59825
In [28]:
with open('diagram.csv', 'rb') as fd:
    text = fd.read()
text[:100]
Out[28]:
b'0.036950897,-19.812012\n0.03500012,32.59825\n0.2093362,42.75399\n0.25276598,9.813249\n0.2743527,-36.1325'
In [29]:
with open('cat.jpg', 'rb') as fd:
    data = fd.read(40)
data
Out[29]:
b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xff\xe2\x0cXICC_PROFILE\x00\x01\x01\x00\x00'
In [30]:
from PIL import Image
import numpy as np
In [31]:
with Image.open('cat.jpg') as img:
    a = np.array(img)
print(a)
a.dtype
[[[ 87 132  73]
  [ 90 128  67]
  [ 95 136  80]
  ...
  [ 83 125  49]
  [ 97 134  57]
  [101 135  61]]

 [[107 145  88]
  [107 138  70]
  [ 91 135  48]
  ...
  [ 76 123  43]
  [ 92 133  54]
  [104 145  67]]

 [[119 151  86]
  [119 149  79]
  [107 148  46]
  ...
  [ 74 123  44]
  [ 83 130  52]
  [ 81 129  55]]

 ...

 [[157 145 133]
  [142 146 129]
  [144 147 136]
  ...
  [180 159 164]
  [196 173 165]
  [113 101  89]]

 [[152 135 127]
  [111 108 119]
  [154 134 159]
  ...
  [121 102 106]
  [161 147 134]
  [210 193 183]]

 [[116 124 103]
  [ 86  90  93]
  [ 41  52  72]
  ...
  [161 160 156]
  [148 142 130]
  [191 173 153]]]
Out[31]:
dtype('uint8')
In [32]:
# img
In [33]:
plt.imshow(a)
Out[33]:
<matplotlib.image.AxesImage at 0x7fd1c14a8650>
In [34]:
os.listdir()
Out[34]:
['.ipynb_checkpoints',
 '20.10.19',
 'freddi.dat',
 'diagram.csv',
 'cat.jpg',
 'V404Cyg.txt.gz',
 'Untitled.html',
 'io.html',
 'test.fits',
 'tmp.dat',
 'cat.txt',
 'cat.npy',
 'cat.npz',
 'io1.ipynb']
In [35]:
import gzip
In [36]:
with gzip.open('V404Cyg.txt.gz') as f:
    for i, line in zip(range(30), f):
        print(f'{i}: {line.decode()}')
0: JD,Magnitude,Uncertainty,HQuncertainty,Band,Observer Code,Comment Code(s),Comp Star 1,Comp Star 2,Charts,Comments,Transfomed,Airmass,Validation Flag,Cmag,Kmag,HJD,Star Name,Observer Affiliation,Measurement Method,Grouping Method,ADS Reference,Digitizer,Credit

1: 2447674.538,11.9,,,Vis.,KRT,,,,,,,,V,,,,V404 CYG,,STD,,,,

2: 2447680.449,14.5,,,Vis.,BMU,,,,,,,,V,,,,V404 CYG,KNVWS,STD,,,,

3: 2447680.521,14.0,,,Vis.,KRT,,,,,,,,V,,,,V404 CYG,,STD,,,,

4: 2447685.05,14.2,,,Vis.,KOA,,,,,,,,V,,,,V404 CYG,,STD,,,,

5: 2447685.9,<14.0,,,Vis.,SCE,,,,,,,,V,,,,V404 CYG,,STD,,,,

6: 2447690.467,14.8,,,Vis.,KRT,,,,,,,,V,,,,V404 CYG,,STD,,,,

7: 2447691.449,15.0,,,Vis.,KRT,,,,,,,,V,,,,V404 CYG,,STD,,,,

8: 2447696.84,<13.3,,,Vis.,SCE,,,,,,,,V,,,,V404 CYG,,STD,,,,

9: 2447706.79,14.8,,,Vis.,SCE,,,,,,,,V,,,,V404 CYG,,STD,,,,

10: 2447717.7,<15.1,,,Vis.,GRI,,,,,,,,V,,,,V404 CYG,,STD,,,,

11: 2447717.7,15.3,,,Vis.,SCE,,,,,,,,V,,,,V404 CYG,,STD,,,,

12: 2447719.61,<14.0,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

13: 2447736.62,<14.5,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

14: 2447744.4868,<14.5,,,Vis.,MAR,,,,,,,,V,,,,V404 CYG,,STD,,,,

15: 2447748.4708,<14.5,,,Vis.,MAR,,,,,,,,V,,,,V404 CYG,,STD,,,,

16: 2447748.59,<14.3,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

17: 2447762.37,<13.6,,,Vis.,SCZ,,,,,,,,V,,,,V404 CYG,AFOEV,STD,,,,

18: 2447763.61,<14.8,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

19: 2447769.59,<14.5,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

20: 2447772.59,<14.5,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

21: 2447773.58,<14.8,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

22: 2447774.58,<14.8,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

23: 2447793.4,<14.0,,,Vis.,FRF,,,,,,,,V,,,,V404 CYG,MCSE,STD,,,,

24: 2447794.58,<14.5,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

25: 2447804.66,<14.8,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

26: 2447805.54,<14.8,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

27: 2447823.55,<14.5,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

28: 2447825.62,<14.5,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

29: 2447848.55,<14.5,,,Vis.,BRJ,,,,,,,,V,,,,V404 CYG,,STD,,,,

In [37]:
np.loadtxt('diagram.csv', delimiter=',')
Out[37]:
array([[ 3.6950897e-02, -1.9812012e+01],
       [ 3.5000120e-02,  3.2598250e+01],
       [ 2.0933620e-01,  4.2753990e+01],
       [ 2.5276598e-01,  9.8132490e+00],
       [ 2.7435270e-01, -3.6132540e+01],
       [ 2.7199373e-01, -7.7606960e+01],
       [ 4.4834232e-01,  3.9542206e+02],
       [ 5.0287396e-01,  4.1046777e+02],
       [ 4.9865913e-01,  4.4323727e+02],
       [ 6.3103210e-01,  3.2257190e+02],
       [ 9.0020174e-01,  9.6505670e+01],
       [ 9.0072380e-01,  2.1659071e+02],
       [ 8.0121980e-01,  3.8078067e+02],
       [ 8.9946604e-01,  4.2838660e+02],
       [ 8.9804685e-01,  6.0306525e+02],
       [ 1.0035977e+00,  8.2749520e+02],
       [ 1.1005150e+00,  5.6943005e+02],
       [ 1.1055652e+00,  7.2879663e+02],
       [ 1.3991741e+00,  6.1179395e+02],
       [ 1.6995230e+00,  1.0427968e+03],
       [ 2.0069914e+00,  1.1069563e+03],
       [ 1.9971569e+00,  8.4935736e+02],
       [ 2.0035028e+00,  8.0566150e+02],
       [ 1.9957709e+00,  5.3058610e+02]])
In [38]:
table = np.genfromtxt('diagram.csv', delimiter=',', names='x,y')
table['x']
table[2]
rec = np.rec.array(table)
rec.x
Out[38]:
array([0.0369509 , 0.03500012, 0.2093362 , 0.25276598, 0.2743527 ,
       0.27199373, 0.44834232, 0.50287396, 0.49865913, 0.6310321 ,
       0.90020174, 0.9007238 , 0.8012198 , 0.89946604, 0.89804685,
       1.0035977 , 1.100515  , 1.1055652 , 1.3991741 , 1.699523  ,
       2.0069914 , 1.9971569 , 2.0035028 , 1.9957709 ])
In [39]:
def convert_magn(b):
    if b.startswith(b'<'):
        return 999
    return b
    

table = np.genfromtxt(
    'V404Cyg.txt.gz',
    delimiter=',',
    usecols=(0, 1, 2),
    names=True,
    filling_values=0.0,
    converters={1: convert_magn},
)
In [40]:
table[~np.isnan(table['Uncertainty'])]
Out[40]:
array([(2447674.538  ,  11.9, 0.), (2447680.449  ,  14.5, 0.),
       (2447680.521  ,  14. , 0.), ..., (2459142.88889, 999. , 0.),
       (2459145.3431 , 999. , 0.), (2459146.84931, 999. , 0.)],
      dtype=[('JD', '<f8'), ('Magnitude', '<f8'), ('Uncertainty', '<f8')])
In [41]:
plt.plot(table['JD'], table['Magnitude'], 'x')
plt.ylim([20, 10])
Out[41]:
(20.0, 10.0)
In [42]:
import pandas as pd
In [43]:
df = pd.read_csv('V404Cyg.txt.gz', low_memory=False)
print([df[column].dtype for column in df.columns])
df
[dtype('float64'), dtype('O'), dtype('float64'), dtype('float64'), dtype('O'), dtype('O'), dtype('O'), dtype('O'), dtype('O'), dtype('O'), dtype('O'), dtype('float64'), dtype('float64'), dtype('O'), dtype('float64'), dtype('float64'), dtype('float64'), dtype('O'), dtype('O'), dtype('O'), dtype('O'), dtype('float64'), dtype('float64'), dtype('float64')]
Out[43]:
JD Magnitude Uncertainty HQuncertainty Band Observer Code Comment Code(s) Comp Star 1 Comp Star 2 Charts ... Cmag Kmag HJD Star Name Observer Affiliation Measurement Method Grouping Method ADS Reference Digitizer Credit
0 2.447675e+06 11.9 NaN NaN Vis. KRT NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
1 2.447680e+06 14.5 NaN NaN Vis. BMU NaN NaN NaN NaN ... NaN NaN NaN V404 CYG KNVWS STD NaN NaN NaN NaN
2 2.447681e+06 14.0 NaN NaN Vis. KRT NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
3 2.447685e+06 14.2 NaN NaN Vis. KOA NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
4 2.447686e+06 <14.0 NaN NaN Vis. SCE NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
80707 2.459137e+06 <14.9 NaN NaN Vis. PYG U <149 NaN AAVSO 1346CXO ... NaN NaN NaN V404 CYG BAA-VSS STD NaN NaN NaN NaN
80708 2.459139e+06 <14.4 NaN NaN Vis. MUY NaN 144 0 X19001DUP ... NaN NaN NaN V404 CYG VVS STD NaN NaN NaN NaN
80709 2.459143e+06 <15.6 NaN NaN Vis. LMK NaN 156 NaN 2169dbs ... NaN NaN NaN V404 CYG AAVSO STD NaN NaN NaN NaN
80710 2.459145e+06 <14.4 NaN NaN Vis. MUY NaN 144 0 X19001DUP ... NaN NaN NaN V404 CYG VVS STD NaN NaN NaN NaN
80711 2.459147e+06 <15.2 NaN NaN Vis. LMK NaN 152 NaN 2169dbs ... NaN NaN NaN V404 CYG AAVSO STD NaN NaN NaN NaN

80712 rows × 24 columns

In [44]:
good = df[~df['Magnitude'].str.startswith('<')]
good.JD
Out[44]:
0        2.447675e+06
1        2.447680e+06
2        2.447681e+06
3        2.447685e+06
5        2.447690e+06
             ...     
80702    2.459136e+06
80703    2.459137e+06
80704    2.459137e+06
80705    2.459137e+06
80706    2.459137e+06
Name: JD, Length: 73608, dtype: float64
In [45]:
good.loc[4]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2645             try:
-> 2646                 return self._engine.get_loc(key)
   2647             except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 4

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-45-9d10255a49ea> in <module>
----> 1 good.loc[4]

/opt/conda/lib/python3.7/site-packages/pandas/core/indexing.py in __getitem__(self, key)
   1766 
   1767             maybe_callable = com.apply_if_callable(key, self.obj)
-> 1768             return self._getitem_axis(maybe_callable, axis=axis)
   1769 
   1770     def _is_scalar_access(self, key: Tuple):

/opt/conda/lib/python3.7/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
   1963         # fall thru to straight lookup
   1964         self._validate_key(key, axis)
-> 1965         return self._get_label(key, axis=axis)
   1966 
   1967 

/opt/conda/lib/python3.7/site-packages/pandas/core/indexing.py in _get_label(self, label, axis)
    623             raise IndexingError("no slices here, handle elsewhere")
    624 
--> 625         return self.obj._xs(label, axis=axis)
    626 
    627     def _get_loc(self, key: int, axis: int):

/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py in xs(self, key, axis, level, drop_level)
   3535             loc, new_index = self.index.get_loc_level(key, drop_level=drop_level)
   3536         else:
-> 3537             loc = self.index.get_loc(key)
   3538 
   3539             if isinstance(loc, np.ndarray):

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2646                 return self._engine.get_loc(key)
   2647             except KeyError:
-> 2648                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2649         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   2650         if indexer.ndim > 1 or indexer.size > 1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 4
In [46]:
df.iloc[4]
Out[46]:
JD                      2.44769e+06
Magnitude                     <14.0
Uncertainty                     NaN
HQuncertainty                   NaN
Band                           Vis.
Observer Code                   SCE
Comment Code(s)                 NaN
Comp Star 1                     NaN
Comp Star 2                     NaN
Charts                          NaN
Comments                        NaN
Transfomed                      NaN
Airmass                         NaN
Validation Flag                   V
Cmag                            NaN
Kmag                            NaN
HJD                             NaN
Star Name                  V404 CYG
Observer Affiliation            NaN
Measurement Method              STD
Grouping Method                 NaN
ADS Reference                   NaN
Digitizer                       NaN
Credit                          NaN
Name: 4, dtype: object
In [47]:
df.loc[[1, 2, 3, 10, 0, 1]]
Out[47]:
JD Magnitude Uncertainty HQuncertainty Band Observer Code Comment Code(s) Comp Star 1 Comp Star 2 Charts ... Cmag Kmag HJD Star Name Observer Affiliation Measurement Method Grouping Method ADS Reference Digitizer Credit
1 2447680.449 14.5 NaN NaN Vis. BMU NaN NaN NaN NaN ... NaN NaN NaN V404 CYG KNVWS STD NaN NaN NaN NaN
2 2447680.521 14.0 NaN NaN Vis. KRT NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
3 2447685.050 14.2 NaN NaN Vis. KOA NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
10 2447717.700 15.3 NaN NaN Vis. SCE NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
0 2447674.538 11.9 NaN NaN Vis. KRT NaN NaN NaN NaN ... NaN NaN NaN V404 CYG NaN STD NaN NaN NaN NaN
1 2447680.449 14.5 NaN NaN Vis. BMU NaN NaN NaN NaN ... NaN NaN NaN V404 CYG KNVWS STD NaN NaN NaN NaN

6 rows × 24 columns

In [48]:
df['JD']
Out[48]:
0        2.447675e+06
1        2.447680e+06
2        2.447681e+06
3        2.447685e+06
4        2.447686e+06
             ...     
80707    2.459137e+06
80708    2.459139e+06
80709    2.459143e+06
80710    2.459145e+06
80711    2.459147e+06
Name: JD, Length: 80712, dtype: float64
In [49]:
df[['JD', 'Magnitude']]
Out[49]:
JD Magnitude
0 2.447675e+06 11.9
1 2.447680e+06 14.5
2 2.447681e+06 14.0
3 2.447685e+06 14.2
4 2.447686e+06 <14.0
... ... ...
80707 2.459137e+06 <14.9
80708 2.459139e+06 <14.4
80709 2.459143e+06 <15.6
80710 2.459145e+06 <14.4
80711 2.459147e+06 <15.2

80712 rows × 2 columns

In [50]:
def convert_magn(s):
    if s.startswith('<'):
        s = s[1:]
    return float(s)


df['m'] = df.Magnitude.map(convert_magn)
df['is_upper_limit'] = df.Magnitude.str.startswith('<')
df.m
Out[50]:
0        11.9
1        14.5
2        14.0
3        14.2
4        14.0
         ... 
80707    14.9
80708    14.4
80709    15.6
80710    14.4
80711    15.2
Name: m, Length: 80712, dtype: float64
In [51]:
df.is_upper_limit
Out[51]:
0        False
1        False
2        False
3        False
4         True
         ...  
80707     True
80708     True
80709     True
80710     True
80711     True
Name: is_upper_limit, Length: 80712, dtype: bool
In [52]:
plt.plot(df.JD[~df.is_upper_limit], df.m[~df.is_upper_limit], 'x')
plt.plot(df.JD[df.is_upper_limit], df.m[df.is_upper_limit], 'v')
Out[52]:
[<matplotlib.lines.Line2D at 0x7fd1a946a450>]
In [53]:
with open('tmp.dat', 'x') as fh:
    fh.write('hello\n')
---------------------------------------------------------------------------
FileExistsError                           Traceback (most recent call last)
<ipython-input-53-7903543c5c48> in <module>
----> 1 with open('tmp.dat', 'x') as fh:
      2     fh.write('hello\n')

FileExistsError: [Errno 17] File exists: 'tmp.dat'
In [54]:
!cat tmp.dat
hello
In [55]:
with open('tmp.dat', 'w') as fh:
    fh.write('hello\n')
In [56]:
np.savetxt('cat.txt', a.sum(axis=2))
In [57]:
!head -n1 cat.txt
2.920000000000000000e+02 2.850000000000000000e+02 3.110000000000000000e+02 4.750000000000000000e+02 7.110000000000000000e+02 6.350000000000000000e+02 6.190000000000000000e+02 7.180000000000000000e+02 7.430000000000000000e+02 7.420000000000000000e+02 7.120000000000000000e+02 3.790000000000000000e+02 2.800000000000000000e+02 2.210000000000000000e+02 1.840000000000000000e+02 1.870000000000000000e+02 3.190000000000000000e+02 4.080000000000000000e+02 3.560000000000000000e+02 2.800000000000000000e+02 2.560000000000000000e+02 2.870000000000000000e+02 2.920000000000000000e+02 2.940000000000000000e+02 2.550000000000000000e+02 2.010000000000000000e+02 2.190000000000000000e+02 2.350000000000000000e+02 2.740000000000000000e+02 3.050000000000000000e+02 2.960000000000000000e+02 3.130000000000000000e+02 2.930000000000000000e+02 2.510000000000000000e+02 2.250000000000000000e+02 2.240000000000000000e+02 1.940000000000000000e+02 2.200000000000000000e+02 2.210000000000000000e+02 2.080000000000000000e+02 2.000000000000000000e+02 2.110000000000000000e+02 2.040000000000000000e+02 2.280000000000000000e+02 2.590000000000000000e+02 2.690000000000000000e+02 2.400000000000000000e+02 2.200000000000000000e+02 2.100000000000000000e+02 1.860000000000000000e+02 2.300000000000000000e+02 3.070000000000000000e+02 3.610000000000000000e+02 4.110000000000000000e+02 3.890000000000000000e+02 3.680000000000000000e+02 2.920000000000000000e+02 2.740000000000000000e+02 2.850000000000000000e+02 2.930000000000000000e+02 3.330000000000000000e+02 3.260000000000000000e+02 3.240000000000000000e+02 2.940000000000000000e+02 2.430000000000000000e+02 1.890000000000000000e+02 2.030000000000000000e+02 2.350000000000000000e+02 2.510000000000000000e+02 2.750000000000000000e+02 2.550000000000000000e+02 2.440000000000000000e+02 2.160000000000000000e+02 2.030000000000000000e+02 2.020000000000000000e+02 2.490000000000000000e+02 2.770000000000000000e+02 2.810000000000000000e+02 2.520000000000000000e+02 2.800000000000000000e+02 2.760000000000000000e+02 2.790000000000000000e+02 2.720000000000000000e+02 2.750000000000000000e+02 3.440000000000000000e+02 3.380000000000000000e+02 3.370000000000000000e+02 3.090000000000000000e+02 2.510000000000000000e+02 2.520000000000000000e+02 2.460000000000000000e+02 2.160000000000000000e+02 2.100000000000000000e+02 2.390000000000000000e+02 2.180000000000000000e+02 2.240000000000000000e+02 2.170000000000000000e+02 1.640000000000000000e+02 1.600000000000000000e+02 1.630000000000000000e+02 1.810000000000000000e+02 2.090000000000000000e+02 1.830000000000000000e+02 1.600000000000000000e+02 1.660000000000000000e+02 1.520000000000000000e+02 1.700000000000000000e+02 1.600000000000000000e+02 1.420000000000000000e+02 1.880000000000000000e+02 1.830000000000000000e+02 2.100000000000000000e+02 1.780000000000000000e+02 1.430000000000000000e+02 1.480000000000000000e+02 1.300000000000000000e+02 1.410000000000000000e+02 1.860000000000000000e+02 1.960000000000000000e+02 2.630000000000000000e+02 3.480000000000000000e+02 3.460000000000000000e+02 3.090000000000000000e+02 2.550000000000000000e+02 1.830000000000000000e+02 1.390000000000000000e+02 1.390000000000000000e+02 1.200000000000000000e+02 1.050000000000000000e+02 1.460000000000000000e+02 2.200000000000000000e+02 2.750000000000000000e+02 2.940000000000000000e+02 2.620000000000000000e+02 2.710000000000000000e+02 2.490000000000000000e+02 2.520000000000000000e+02 2.210000000000000000e+02 1.870000000000000000e+02 1.460000000000000000e+02 1.790000000000000000e+02 3.690000000000000000e+02 4.160000000000000000e+02 3.510000000000000000e+02 1.890000000000000000e+02 2.200000000000000000e+02 2.450000000000000000e+02 2.760000000000000000e+02 3.410000000000000000e+02 3.910000000000000000e+02 3.520000000000000000e+02 2.680000000000000000e+02 2.290000000000000000e+02 1.750000000000000000e+02 1.790000000000000000e+02 2.310000000000000000e+02 3.250000000000000000e+02 4.150000000000000000e+02 4.730000000000000000e+02 4.320000000000000000e+02 3.540000000000000000e+02 2.780000000000000000e+02 2.200000000000000000e+02 2.320000000000000000e+02 2.360000000000000000e+02 2.850000000000000000e+02 2.420000000000000000e+02 2.430000000000000000e+02 2.630000000000000000e+02 2.620000000000000000e+02 2.400000000000000000e+02 2.280000000000000000e+02 2.830000000000000000e+02 3.140000000000000000e+02 2.800000000000000000e+02 2.200000000000000000e+02 1.300000000000000000e+02 1.420000000000000000e+02 2.180000000000000000e+02 2.250000000000000000e+02 2.360000000000000000e+02 1.900000000000000000e+02 2.410000000000000000e+02 3.050000000000000000e+02 4.180000000000000000e+02 4.490000000000000000e+02 4.430000000000000000e+02 4.030000000000000000e+02 3.520000000000000000e+02 3.610000000000000000e+02 3.730000000000000000e+02 3.990000000000000000e+02 3.710000000000000000e+02 3.040000000000000000e+02 2.450000000000000000e+02 2.090000000000000000e+02 1.590000000000000000e+02 2.090000000000000000e+02 1.860000000000000000e+02 1.660000000000000000e+02 2.060000000000000000e+02 2.720000000000000000e+02 3.060000000000000000e+02 3.480000000000000000e+02 3.280000000000000000e+02 2.760000000000000000e+02 1.960000000000000000e+02 2.010000000000000000e+02 2.730000000000000000e+02 3.060000000000000000e+02 2.690000000000000000e+02 2.350000000000000000e+02 2.150000000000000000e+02 1.750000000000000000e+02 1.540000000000000000e+02 1.910000000000000000e+02 1.920000000000000000e+02 1.870000000000000000e+02 2.180000000000000000e+02 2.810000000000000000e+02 3.070000000000000000e+02 3.250000000000000000e+02 3.000000000000000000e+02 3.350000000000000000e+02 3.580000000000000000e+02 3.760000000000000000e+02 3.810000000000000000e+02 3.870000000000000000e+02 3.470000000000000000e+02 3.080000000000000000e+02 3.340000000000000000e+02 4.140000000000000000e+02 4.520000000000000000e+02 4.670000000000000000e+02 4.200000000000000000e+02 3.550000000000000000e+02 3.260000000000000000e+02 3.090000000000000000e+02 3.020000000000000000e+02 2.520000000000000000e+02 2.290000000000000000e+02 1.890000000000000000e+02 3.760000000000000000e+02 4.290000000000000000e+02 4.240000000000000000e+02 2.300000000000000000e+02 2.110000000000000000e+02 2.740000000000000000e+02 3.120000000000000000e+02 3.370000000000000000e+02 3.070000000000000000e+02 2.460000000000000000e+02 1.950000000000000000e+02 1.420000000000000000e+02 1.250000000000000000e+02 1.380000000000000000e+02 1.640000000000000000e+02 1.750000000000000000e+02 2.040000000000000000e+02 1.930000000000000000e+02 1.600000000000000000e+02 1.580000000000000000e+02 2.020000000000000000e+02 1.940000000000000000e+02 1.920000000000000000e+02 1.570000000000000000e+02 1.750000000000000000e+02 1.900000000000000000e+02 2.150000000000000000e+02 2.400000000000000000e+02 2.050000000000000000e+02 2.310000000000000000e+02 2.260000000000000000e+02 2.130000000000000000e+02 2.070000000000000000e+02 2.150000000000000000e+02 2.200000000000000000e+02 2.670000000000000000e+02 2.960000000000000000e+02 2.480000000000000000e+02 2.700000000000000000e+02 2.510000000000000000e+02 2.270000000000000000e+02 1.980000000000000000e+02 1.520000000000000000e+02 1.430000000000000000e+02 1.550000000000000000e+02 1.840000000000000000e+02 3.180000000000000000e+02 3.910000000000000000e+02 3.030000000000000000e+02 2.400000000000000000e+02 6.600000000000000000e+02 7.170000000000000000e+02 7.250000000000000000e+02 5.980000000000000000e+02 2.890000000000000000e+02 2.540000000000000000e+02 4.960000000000000000e+02 7.580000000000000000e+02 7.380000000000000000e+02 7.530000000000000000e+02 7.410000000000000000e+02 7.250000000000000000e+02 7.190000000000000000e+02 6.940000000000000000e+02 6.260000000000000000e+02 2.040000000000000000e+02 2.070000000000000000e+02 5.920000000000000000e+02 7.590000000000000000e+02 7.480000000000000000e+02 7.550000000000000000e+02 4.750000000000000000e+02 3.630000000000000000e+02 4.420000000000000000e+02 3.490000000000000000e+02 3.910000000000000000e+02 4.720000000000000000e+02 6.070000000000000000e+02 6.090000000000000000e+02 3.730000000000000000e+02 1.490000000000000000e+02 1.700000000000000000e+02 1.480000000000000000e+02 1.450000000000000000e+02 1.550000000000000000e+02 2.030000000000000000e+02 2.020000000000000000e+02 1.820000000000000000e+02 2.050000000000000000e+02 2.250000000000000000e+02 2.390000000000000000e+02 2.020000000000000000e+02 1.600000000000000000e+02 2.090000000000000000e+02 2.440000000000000000e+02 2.240000000000000000e+02 2.290000000000000000e+02 1.820000000000000000e+02 1.320000000000000000e+02 1.360000000000000000e+02 1.590000000000000000e+02 1.680000000000000000e+02 1.490000000000000000e+02 1.570000000000000000e+02 1.370000000000000000e+02 1.820000000000000000e+02 1.780000000000000000e+02 1.710000000000000000e+02 2.010000000000000000e+02 1.790000000000000000e+02 1.650000000000000000e+02 2.320000000000000000e+02 2.980000000000000000e+02 6.550000000000000000e+02 7.520000000000000000e+02 7.560000000000000000e+02 7.170000000000000000e+02 2.870000000000000000e+02 1.770000000000000000e+02 2.210000000000000000e+02 2.110000000000000000e+02 1.600000000000000000e+02 1.640000000000000000e+02 1.680000000000000000e+02 1.920000000000000000e+02 1.750000000000000000e+02 2.010000000000000000e+02 1.930000000000000000e+02 2.290000000000000000e+02 2.490000000000000000e+02 2.560000000000000000e+02 3.030000000000000000e+02 3.980000000000000000e+02 3.910000000000000000e+02 3.500000000000000000e+02 2.250000000000000000e+02 1.880000000000000000e+02 2.640000000000000000e+02 2.750000000000000000e+02 3.400000000000000000e+02 3.410000000000000000e+02 2.520000000000000000e+02 2.180000000000000000e+02 4.970000000000000000e+02 7.470000000000000000e+02 7.370000000000000000e+02 6.920000000000000000e+02 7.190000000000000000e+02 7.430000000000000000e+02 7.420000000000000000e+02 7.520000000000000000e+02 7.070000000000000000e+02 7.120000000000000000e+02 7.090000000000000000e+02 6.070000000000000000e+02 7.330000000000000000e+02 7.430000000000000000e+02 7.220000000000000000e+02 6.600000000000000000e+02 6.350000000000000000e+02 7.170000000000000000e+02 6.790000000000000000e+02 3.300000000000000000e+02 2.920000000000000000e+02 7.050000000000000000e+02 7.540000000000000000e+02 7.440000000000000000e+02 7.500000000000000000e+02 4.960000000000000000e+02 2.600000000000000000e+02 2.480000000000000000e+02 2.630000000000000000e+02 2.530000000000000000e+02 3.900000000000000000e+02 7.510000000000000000e+02 7.520000000000000000e+02 7.550000000000000000e+02 7.580000000000000000e+02 7.620000000000000000e+02 7.550000000000000000e+02 7.510000000000000000e+02 7.610000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.530000000000000000e+02 7.560000000000000000e+02 7.620000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.560000000000000000e+02 7.560000000000000000e+02 7.590000000000000000e+02 7.620000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.590000000000000000e+02 7.580000000000000000e+02 7.580000000000000000e+02 7.600000000000000000e+02 7.630000000000000000e+02 7.470000000000000000e+02 7.530000000000000000e+02 7.560000000000000000e+02 7.510000000000000000e+02 7.590000000000000000e+02 7.470000000000000000e+02 7.600000000000000000e+02 6.270000000000000000e+02 5.090000000000000000e+02 5.100000000000000000e+02 4.980000000000000000e+02 4.350000000000000000e+02 3.940000000000000000e+02 3.540000000000000000e+02 2.660000000000000000e+02 2.450000000000000000e+02 2.040000000000000000e+02 2.560000000000000000e+02 2.700000000000000000e+02 3.030000000000000000e+02 3.140000000000000000e+02 3.040000000000000000e+02 2.940000000000000000e+02 2.980000000000000000e+02 3.070000000000000000e+02 3.240000000000000000e+02 3.190000000000000000e+02 2.680000000000000000e+02 2.540000000000000000e+02 2.050000000000000000e+02 1.920000000000000000e+02 1.870000000000000000e+02 1.970000000000000000e+02 2.050000000000000000e+02 2.130000000000000000e+02 2.320000000000000000e+02 2.480000000000000000e+02 2.410000000000000000e+02 2.730000000000000000e+02 2.390000000000000000e+02 2.330000000000000000e+02 2.570000000000000000e+02 2.880000000000000000e+02 2.970000000000000000e+02
In [58]:
np.save('cat.npy', a)
In [59]:
b = np.load('cat.npy')
np.testing.assert_array_equal(a, b)
In [60]:
np.savez('cat.npz', a)
In [61]:
npz = np.load('cat.npz')
for b in npz.items():
    print(b)
('arr_0', array([[[ 87, 132,  73],
        [ 90, 128,  67],
        [ 95, 136,  80],
        ...,
        [ 83, 125,  49],
        [ 97, 134,  57],
        [101, 135,  61]],

       [[107, 145,  88],
        [107, 138,  70],
        [ 91, 135,  48],
        ...,
        [ 76, 123,  43],
        [ 92, 133,  54],
        [104, 145,  67]],

       [[119, 151,  86],
        [119, 149,  79],
        [107, 148,  46],
        ...,
        [ 74, 123,  44],
        [ 83, 130,  52],
        [ 81, 129,  55]],

       ...,

       [[157, 145, 133],
        [142, 146, 129],
        [144, 147, 136],
        ...,
        [180, 159, 164],
        [196, 173, 165],
        [113, 101,  89]],

       [[152, 135, 127],
        [111, 108, 119],
        [154, 134, 159],
        ...,
        [121, 102, 106],
        [161, 147, 134],
        [210, 193, 183]],

       [[116, 124, 103],
        [ 86,  90,  93],
        [ 41,  52,  72],
        ...,
        [161, 160, 156],
        [148, 142, 130],
        [191, 173, 153]]], dtype=uint8))
In [62]:
import pickle
In [ ]: