bundles / numpy latest / numpy / lib / npyio / NpzFile
ABCMeta
numpy.lib.npyio:NpzFile
source: build-install/usr/lib/python3.14/site-packages/numpy/lib/npyio.py
Signature
def NpzFile ( fid ) Summary
A dictionary-like object with lazy-loading of files in the zipped archive provided on construction.
Extended Summary
NpzFile is used to load files in the NumPy .npz data archive format. It assumes that files in the archive have a .npy extension, other files are ignored.
The arrays and file strings are lazily loaded on either getitem access using obj['key'] or attribute lookup using obj.f.key. A list of all files (without .npy extensions) can be obtained with obj.files and the ZipFile object itself using obj.zip.
Parameters
fid: file, str, or pathlib.PathThe zipped archive to open. This is either a file-like object or a string containing the path to the archive.
own_fid: bool, optionalWhether NpzFile should close the file handle. Requires that
fidis a file-like object.
Attributes
files: list of strList of all files in the archive with a
.npyextension.zip: ZipFile instanceThe ZipFile object initialized with the zipped archive.
f: BagObj instanceAn object on which attribute can be performed as an alternative to getitem access on the NpzFile instance itself.
allow_pickle: bool, optionalAllow loading pickled data. Default: False
pickle_kwargs: dict, optionalAdditional keyword arguments to pass on to pickle.load. These are only useful when loading object arrays saved on Python 2.
max_header_size: int, optionalMaximum allowed size of the header. Large headers may not be safe to load securely and thus require explicitly passing a larger value. See
ast.literal_eval()for details. This option is ignored when allow_pickle is passed. In that case the file is by definition trusted and the limit is unnecessary.
Examples
import numpy as np from tempfile import TemporaryFile outfile = TemporaryFile() x = np.arange(10) y = np.sin(x) np.savez(outfile, x=x, y=y) _ = outfile.seek(0)✓
npz = np.load(outfile) isinstance(npz, np.lib.npyio.NpzFile) npz sorted(npz.files) npz['x'] # getitem access npz.f.x # attribute lookup✓
Aliases
-
numpy.lib._npyio_impl.NpzFile