flopscope.

flopscope.numpy.save

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

Adapted from NumPy docs np.save

Areacore
Typefree
NumPy Refnp.save
Cost
0
Flopscope Context

Save array to .npy file (pickle-free). Cost: 0 FLOPs.

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

fix_imports:bool, optional

The fix_imports flag is deprecated and has no effect.

Deprecated since 2.1.

See also

Notes

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

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

Examples

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