spdl.io.load_npz¶
- load_npz(data: bytes | bytearray | memoryview[bytes], *, max_uncompressed_bytes: int = 1073741824) NpzFile[source]¶
[Experimental] Load a numpy archive file (
npz).It is almost a drop-in replacement for
numpy.load()function, but it only supports the basic use cases.This function uses the C++ implementation of the zip archive reader, which releases the GIL. So it is more efficient than the official NumPy implementation for supported cases.
- Parameters:
data – The data to load.
max_uncompressed_bytes – Maximum cumulative declared uncompressed size of DEFLATE-compressed entries. Defaults to 1 GiB. Increase this explicitly only for trusted archives that require more space.
Added in version 0.7.0: The
max_uncompressed_bytesargument.Changed in version 0.7.0: Arrays backed by stored entries now inherit the source buffer’s writability. Arrays inflated from compressed entries own writable storage independently of the source archive.
Example
>>> x = np.arange(10) >>> y = np.sin(x) >>> >>> with tempfile.TemporaryFile() as f: ... np.savez(f, x=x, y=y) ... f.seek(0) ... data = spdl.io.load_npz(f.read()) ... >>> assert np.array_equal(data["x"], x) >>> assert np.array_equal(data["y"], y)