MCPcopy Index your code
hub / github.com/numpy/numpy / NpzFile

Class NpzFile

numpy/lib/_npyio_impl.py:116–308  ·  view source on GitHub ↗

NpzFile(fid) 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 ignor

Source from the content-addressed store, hash-verified

114
115@set_module('numpy.lib.npyio')
116class NpzFile(Mapping):
117 """
118 NpzFile(fid)
119
120 A dictionary-like object with lazy-loading of files in the zipped
121 archive provided on construction.
122
123 `NpzFile` is used to load files in the NumPy ``.npz`` data archive
124 format. It assumes that files in the archive have a ``.npy`` extension,
125 other files are ignored.
126
127 The arrays and file strings are lazily loaded on either
128 getitem access using ``obj['key']`` or attribute lookup using
129 ``obj.f.key``. A list of all files (without ``.npy`` extensions) can
130 be obtained with ``obj.files`` and the ZipFile object itself using
131 ``obj.zip``.
132
133 Attributes
134 ----------
135 files : list of str
136 List of all files in the archive with a ``.npy`` extension.
137 zip : ZipFile instance
138 The ZipFile object initialized with the zipped archive.
139 f : BagObj instance
140 An object on which attribute can be performed as an alternative
141 to getitem access on the `NpzFile` instance itself.
142 allow_pickle : bool, optional
143 Allow loading pickled data. Default: False
144 pickle_kwargs : dict, optional
145 Additional keyword arguments to pass on to pickle.load.
146 These are only useful when loading object arrays saved on
147 Python 2.
148 max_header_size : int, optional
149 Maximum allowed size of the header. Large headers may not be safe
150 to load securely and thus require explicitly passing a larger value.
151 See :py:func:`ast.literal_eval()` for details.
152 This option is ignored when `allow_pickle` is passed. In that case
153 the file is by definition trusted and the limit is unnecessary.
154
155 Parameters
156 ----------
157 fid : file, str, or pathlib.Path
158 The zipped archive to open. This is either a file-like object
159 or a string containing the path to the archive.
160 own_fid : bool, optional
161 Whether NpzFile should close the file handle.
162 Requires that `fid` is a file-like object.
163
164 Examples
165 --------
166 >>> import numpy as np
167 >>> from tempfile import TemporaryFile
168 >>> outfile = TemporaryFile()
169 >>> x = np.arange(10)
170 >>> y = np.sin(x)
171 >>> np.savez(outfile, x=x, y=y)
172 >>> _ = outfile.seek(0)
173

Callers 1

loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…