NumPy | save method
Start your free 7-days trial now!
save(~) method writes a Numpy array to a file in
The file to which the Numpy array will be written. The
.npy extension will be appended to the filename if the path does not already include it.
The array to save.
Whether or not to use pickling to save the array. If your array has a dtype of object, (e.g. your array contains non-numeric data like strings), then this must be set to
True. If your array has numeric
dtype, then this can be set to
If the dtype is numeric, then opt for
As a general rule of thumb, pickles should not be used if they are not required since different versions of Python and Numpy may interprets pickles differently, and so others may not be able to load the files. Moreover, since reading pickled files involve running arbitrary code in the file, the reader will be susceptible to malicious attacks.
Whether or not to make the saved file readable by Python 2. By default,
x = np.array([3,4,5])np.save("my_data", x)
This saves our array in a file called
my_data.npy, which exists in the same directory as our Python script.