nlcpy.savez
- nlcpy.savez(file, *args, **kwds)[ソース]
Saves several arrays into a single file in uncompressed
.npzformat.If arguments are passed in with no keywords, the corresponding variable names, in the
.npzfile, are 'arr_0', 'arr_1', etc. If keyword arguments are given, the corresponding variable names, in the.npzfile will match the keyword names.- 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, optional
Arrays to save to the file. Arrays will be saved in the file with the keyword names.
参考
saveSaves an array to a binary file in NumPy
.npyformat.savetxtSaves an array to a text file.
savez_compressedSaves several arrays into a single file in compressed
.npzformat.
注釈
The
.npzfile format is a zipped archive of files named after the variables they contain. The archive is not compressed and 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 tempfile import TemporaryFile >>> outfile = TemporaryFile() >>> x = vp.arange(10) >>> y = vp.sin(x)
Using savez with *args, the arrays are saved with default names.
>>> vp.savez(outfile, x, y) >>> _ = outfile.seek(0) # Only needed here to simulate closing & reopening file >>> npzfile = vp.load(outfile) >>> npzfile.files ['arr_0', 'arr_1'] >>> npzfile['arr_0'] array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Using savez with **kwds, the arrays are saved with the keyword names.
>>> outfile = TemporaryFile() >>> vp.savez(outfile, x=x, y=y) >>> _ = outfile.seek(0) >>> npzfile = vp.load(outfile) >>> sorted(npzfile.files) ['x', 'y'] >>> npzfile['x'] array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])