In [1]:
%autosave 30
Autosaving every 30 seconds
In [2]:
import numpy as np
In [3]:
a = np.arange(16).reshape(4, 4)
In [4]:
a
Out[4]:
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
In [5]:
np.save('a.npy', a)
In [6]:
!cat a.npy
�NUMPYv{'descr': '<i8', 'fortran_order': False, 'shape': (4, 4), }                                                          
	

In [8]:
np.savez('a.npz', a, a * 2)
In [9]:
!cat a.npz
PK!����	arr_0.npy�NUMPYv{'descr': '<i8', 'fortran_order': False, 'shape': (4, 4), }                                                          
	
PK!o�d	arr_1.npy�NUMPYv{'descr': '<i8', 'fortran_order': False, 'shape': (4, 4), }                                                          

PK!����	�arr_0.npyPK!o�d	�;arr_1.npyPKnv
In [25]:
x = np.memmap('a.dat', mode='write', shape=(4,4), dtype=np.float64)
x[:] = 1
del x
In [26]:
with open('a.dat', 'rb') as fh:
    number = fh.read(8)
np.frombuffer(number)
Out[26]:
array([1.])
In [27]:
import pickle
In [29]:
data = [1, 2.0, (3.0, 'Hello')]

with open('data.dat', 'wb') as fh:
    pickle.dump(data, fh)
In [30]:
!head data.dat
�]q(KG@G@XHelloq�qe.
In [33]:
with open('data.dat', 'rb') as fh:
    loaded = pickle.load(fh)
    print(loaded)
    assert loaded == data
[1, 2.0, (3.0, 'Hello')]
In [36]:
s = pickle.dumps(data)
In [37]:
loaded = pickle.loads(s)
print(loaded)
assert loaded == data
[1, 2.0, (3.0, 'Hello')]
In [38]:
from joblib import Memory
In [39]:
memory = Memory(location='cache')

@memory.cache
def double(x):
    return x * 2


print(double(1))
print(double(2))
________________________________________________________________________________
[Memory] Calling __main__--home-jovyan-work-__ipython-input__.double...
double(1)
___________________________________________________________double - 0.0s, 0.0min
2
________________________________________________________________________________
[Memory] Calling __main__--home-jovyan-work-__ipython-input__.double...
double(2)
___________________________________________________________double - 0.0s, 0.0min
4
In [40]:
import os
In [42]:
os.listdir('cache/joblib/__main__--home-jovyan-work-__ipython-input__/double/d3ffa92536e9b2aeb96c6d0e11ccd857')
Out[42]:
['output.pkl', 'metadata.json']
In [ ]: