Save a numpy array to disk
In this article we will learn how to save a numpy array to the disk. We will then see how to load it back from the disk into memory.
First, let't import numpy.
# Import modules
import numpy as np
We will generate an array to demonstrate saving and loading.
myarray = np.arange(10)
Numpy arrays can be save to the disk to the binary .npy
format by using the save
method.
np.save("C:\\temp\\arr.npy", myarray)
Once saved, it can be retrived from the disk by using the load
method.
my_other_array = np.load("C:\\temp\\arr.npy")
my_other_array
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])