numpy.save(file, arr, allow_pickle=True, fix_imports=True)[source]
Save an array to a binary file in NumPy .npy
format.
Parameters: |
file : file or str 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, a 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 Python 2 and Python 3). Default: True fix_imports : bool, optional Only useful in forcing objects in object arrays on Python 3 to be pickled in a Python 2 compatible way. If arr : array_like Array data to be saved. |
---|
For a description of the .npy
format, see the module docstring of numpy.lib.format
or the Numpy Enhancement Proposal http://docs.scipy.org/doc/numpy/neps/npy-format.html
>>> from tempfile import TemporaryFile >>> outfile = TemporaryFile()
>>> x = np.arange(10) >>> np.save(outfile, x)
>>> outfile.seek(0) # Only needed here to simulate closing & reopening file >>> np.load(outfile) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
© 2008–2016 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.save.html