A dictionary-like object with lazy-loading of files in the zipped archive provided on construction.
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
.
The zipped archive to open. This is either a file-like object or a string containing the path to the archive.
Whether NpzFile should close the file handle. Requires that fid
is a file-like object.
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) True >>> npz NpzFile 'object' with keys: x, y >>> sorted(npz.files) ['x', 'y'] >>> npz['x'] # getitem access array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> npz.f.x # attribute lookup array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
List of all files in the archive with a .npy
extension.
The ZipFile object initialized with the zipped archive.
An object on which attribute can be performed as an alternative to getitem access on the NpzFile
instance itself.
Allow loading pickled data. Default: False
Additional keyword arguments to pass on to pickle.load. These are only useful when loading object arrays saved on Python 2.
Maximum 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.
Methods
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4