Expand description
NumPy .npz archives (numpy.savez, numpy.savez_compressed and numpy.load).
An .npz file is a ZIP archive whose members are .npy files named <name>.npy. This module
reads and writes the ZIP container itself:
- The reader finds the end-of-central-directory record, and reads each member’s name, method, sizes, CRC-32 and offset from the central directory, not from the local headers, which may hold zeros when a data descriptor follows the data. ZIP64 (sizes and offsets above 4 GiB, or 65 535 members and more) is read. Members may be stored (method 0) or deflated (8); each is checked against its CRC-32 and its declared size.
- The writer stores (
savez) or deflates (savez_compressed) each member, and uses ZIP64 records exactly when a size or an offset needs them. - Safety: encrypted members, other compression methods, path-traversal and duplicate names, truncated archives, size and CRC mismatches and decompression bombs are errors, never panics. Nothing is written to the file system by name.
See the book entry Data files.
Structs§
- NpzArchive
- A parsed
.npzarchive, borrowing its bytes. Members are decoded on demand.
Functions§
- npz_
decode - Reads every
.npymember of an.npzarchive, as(name, array)pairs in archive order with.npyremoved from the names. Members of other names are skipped. - npz_
encode - Builds an
.npzarchive from named arrays (numpy.savez, ornumpy.savez_compressedwhencompressed): each array becomes the member<name>.npy. Names must be non-empty, distinct, and free of/,\,..and a trailing.npy. Sizes and offsets that do not fit 32 bits get ZIP64 records. - npz_
encode_ positional - As
npz_encode, for arrays without names: they are calledarr_0,arr_1, … asnumpy.savezdoes. - npz_
encode_ zip64 - As
npz_encode, with ZIP64 records on every member and on the end of the directory even though the sizes do not need them (what NumPy’ssavezdoes for the local headers). Mainly for testing readers. - read_
npz_ file - Reads an
.npzfile. - write_
npz_ file - Writes an
.npzfile.