nlcpy.savez_compressed
- nlcpy.savez_compressed(file, *args, **kwds)[ソース]
Saves several arrays into a single file in compressed
.npzformat.If keyword arguments are given, then filenames are taken from the keywords. If arguments are passed in with no keywords, then stored file names are arr_0, arr_1, etc.
- Parameters
- filestr or file
Either the file name (string) or an open file (file-like object) where the data will be saved. If file is a string or a Path, the
.npzextension will be appended to the file name if it is not already there.- argsArguments, optional
Arrays to save to the file. Since it is not possible for Python to know the names of the arrays outside
savez(), the arrays will be saved with names "arr_0", "arr_1", and so on. These arguments can be any expression.- kwdskeyword arguments
Arrays to save to the file. Arrays will be saved in the file with the keyword names.
参考
注釈
The
.npzfile format is a zipped archive of files named after the variables they contain. The archive is compressed withzipfile.ZIP_DEFLATEDand each file in the archive contains one variable in.npyformat. For a description of the.npyformat, see numpy.lib.format.When opening the saved
.npzfile withload()a NpzFile object is returned. This is a dictionary-like object which can be queried for its list of arrays (with the.filesattribute), and for the arrays themselves.Examples
>>> import nlcpy as vp >>> from nlcpy import testing >>> test_array = vp.random.rand(3, 2) >>> test_vector = vp.random.rand(4) >>> vp.savez_compressed('/tmp/123', a=test_array, b=test_vector) >>> loaded = vp.load('/tmp/123.npz') >>> vp.testing.assert_array_equal(test_array, loaded['a']) >>> vp.testing.assert_array_equal(test_vector, loaded['b'])