{ } Raw JSON

bundles / numpy 2.4.4 / numpy / save

_ArrayFunctionDispatcher

numpy:save

source: /numpy/lib/_npyio_impl.py :504

Signature

def   save ( file arr allow_pickle = True )

Summary

Save an array to a binary file in NumPy .npy format.

Parameters

file : file, str, or pathlib.Path

File or filename to which the data is saved. If file is a file-object, then the filename is unchanged. If file is a string or Path, a .npy extension will be appended to the filename if it does not already have one.

arr : array_like

Array data to be saved.

allow_pickle : bool, optional

Allow saving object arrays using Python pickles. Reasons for disallowing pickles include security (loading pickled data can execute arbitrary code) and portability (pickled objects may not be loadable on different Python installations, for example if the stored objects require libraries that are not available, and not all pickled data is compatible between different versions of Python). Default: True

Notes

For a description of the .npy format, see numpy.lib.format.

Any data saved to the file is appended to the end of the file.

Examples

import numpy as np
from tempfile import TemporaryFile
outfile = TemporaryFile()
x = np.arange(10)
np.save(outfile, x)
_ = outfile.seek(0) # Only needed to simulate closing & reopening file
np.load(outfile)
with open('test.npy', 'wb') as f:
    np.save(f, np.array([1, 2]))
    np.save(f, np.array([1, 3]))
with open('test.npy', 'rb') as f:
    a = np.load(f)
    b = np.load(f)
print(a, b)

See also

load
savetxt
savez

Save several arrays into a .npz archive

Aliases

  • numpy.save

Referenced by