Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.save

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, 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.npyextension will be appended to the file name if it does not alreadyhave one.

allow_pickle : bool, optional

Allow saving object arrays using Python pickles. Reasons for disallowingpickles include security (loading pickled data can execute arbitrarycode) and portability (pickled objects may not be loadable on differentPython installations, for example if the stored objects require librariesthat are not available, and not all pickled data is compatible betweenPython 2 and Python 3).Default: True

fix_imports : bool, optional

Only useful in forcing objects in object arrays on Python 3 to bepickled in a Python 2 compatible way. Iffix_imports is True, picklewill try to map the new Python 3 names to the old module names used inPython 2, so that the pickle data stream is readable with Python 2.

arr : array_like

Array data to be saved.

See also

savez
Save several arrays into a.npz archive

savetxt,load

Notes

For a description of the.npy format, see the module docstringofnumpy.lib.format or the NumPy Enhancement Proposalhttp://docs.scipy.org/doc/numpy/neps/npy-format.html

Examples

>>>fromtempfileimportTemporaryFile>>>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])

Previous topic

numpy.load

Next topic

numpy.savez

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp