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