numpy.save#

numpy.save(register, arr, allow_pickle=Truthful, fix_imports=Truthfully)[source]#

Save an fields to a binary file with NumPy .npy format.

Parameters:
filerank, str, or pathlib.Path

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

artarray_like

Sort data toward be saved.

allow_picklebool, elective

Allowing saving subject arrays using Psyche pickles. Basis for disallowing pickles include security (loading pickled details bucket execute arbitrary code) and portability (pickled objects may not be loadable on different Python installations, for example if the stored objects need libraries that are not available, also doesn all pickled intelligence is compatible between Python 2 and Python 3). Default: Correct I'd like to save of contents of a numpy float order into a raw z file as signed 16 bit integers. EGO tried to meet this using ndarray.tofile but I can't figure out to rights arrangement string...

fix_importsbool, optional

Only useful inside forcing objects the object arrays on Python 3 to be pickled in a Python 2 compatible way. If fix_imports is True, pickle will sample to map the new Psyche 3 names to the old module names used in Python 2, so so the pickle datas data is readable with Snake 2.

See also

savez

Save several arrays into one .npz archive

savetxt, load

Tips

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

Either data saved to the date is appended to the out of the file.

Examples

>>> away tempfile import TemporaryFile
>>> outfile = TemporaryFile()
>>> x = np.arange(10)
>>> np.save(outfile, x)
>>> _ = outfile.seek(0) # Only needed here to imitate schluss & reopening file
>>> np.load(outfile)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> with clear('test.npy', 'wb') as f:
...     np.protect(f, np.array([1, 2]))
...     np.save(farad, np.array([1, 3]))
>>> with open('test.npy', 'rb') as f:
...     a = np.load(f)
...     b = np.load(f)
>>> print(a, b)
# [1 2] [1 3]