{:check ["true"]}

Index

Persistent Storage of Numpy Data

Persistent Storage

In [2]:
import numpy as np

Numpy can save data to the disk, and load data from disk.

Saving data

In [3]:
#
# Consider an nd-array obtained somehow.
#
data = np.random.rand(6, 3)
data
Out[3]:
array([[0.02537665, 0.36118198, 0.18168319],
       [0.75593436, 0.30382605, 0.70367888],
       [0.83244246, 0.75328304, 0.47474458],
       [0.93640033, 0.89605503, 0.73881676],
       [0.1473916 , 0.89436734, 0.08461609],
       [0.53201269, 0.46728384, 0.20387812]])
In [4]:
#
# We can save it with numpy.save(filename, ndarray)
#
np.save('my_data', data)

Loading Data

In [6]:
#
# We can load the ndarray that is saved in the file.
#
reloaded_data = np.load('my_data.npy')
reloaded_data
Out[6]:
array([[0.02537665, 0.36118198, 0.18168319],
       [0.75593436, 0.30382605, 0.70367888],
       [0.83244246, 0.75328304, 0.47474458],
       [0.93640033, 0.89605503, 0.73881676],
       [0.1473916 , 0.89436734, 0.08461609],
       [0.53201269, 0.46728384, 0.20387812]])
In [ ]: