numpy.savez(file,*args,**kwds)[source]¶Save several arrays into a single file in uncompressed.npz format.
If arguments are passed in with no keywords, the corresponding variablenames, in the.npz file, are ‘arr_0’, ‘arr_1’, etc. If keywordarguments are given, the corresponding variable names, in the.npzfile will match the keyword names.
| Parameters: | file : str or file
args : Arguments, optional
kwds : Keyword arguments, optional
|
|---|---|
| Returns: | None |
See also
savesavetxtsavez_compressed.npz archiveNotes
The.npz file format is a zipped archive of files named after thevariables they contain. The archive is not compressed and each filein the archive contains one variable in.npy format. For adescription of the.npy format, seenumpy.lib.format or theNumPy Enhancement Proposalhttp://docs.scipy.org/doc/numpy/neps/npy-format.html
When opening the saved.npz file withload aNpzFile object isreturned. This is a dictionary-like object which can be queried forits list of arrays (with the.files attribute), and for the arraysthemselves.
Examples
>>>fromtempfileimportTemporaryFile>>>outfile=TemporaryFile()>>>x=np.arange(10)>>>y=np.sin(x)
Usingsavez with *args, the arrays are saved with default names.
>>>np.savez(outfile,x,y)>>>outfile.seek(0)# Only needed here to simulate closing & reopening file>>>npzfile=np.load(outfile)>>>npzfile.files['arr_1', 'arr_0']>>>npzfile['arr_0']array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Usingsavez with **kwds, the arrays are saved with the keyword names.
>>>outfile=TemporaryFile()>>>np.savez(outfile,x=x,y=y)>>>outfile.seek(0)>>>npzfile=np.load(outfile)>>>npzfile.files['y', 'x']>>>npzfile['x']array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])