Compare
NPY vs NPZ
NPY stores one array with dtype and shape. NPZ bundles NPY members in ZIP and provides access by array name.
Which format should you choose?
Choose NPY for one array or memory-mapping numeric data; choose NPZ to deliver multiple arrays together.
Good fit for NPY
Saving one NumPy array in binary form with its type and shape · Passing arrays to NumPy-based scientific and machine-learning workflows
- Preserving dtype and multidimensional shape without text conversion
- Memory-mapping supported non-object arrays for access
Good fit for NPZ
Bundling multiple NumPy arrays in one ZIP archive · Passing named arrays between NumPy scientific-computing workflows
- Storing several arrays in one file
- Choosing uncompressed or compressed ZIP members as needed
Basic information
| Field | NPY | NPZ |
|---|---|---|
| Extension | .npy | .npz |
| MIME type | application/octet-stream | application/zip |
| Common uses | Saving one NumPy array in binary form with its type and shape · Passing arrays to NumPy-based scientific and machine-learning workflows | Bundling multiple NumPy arrays in one ZIP archive · Passing named arrays between NumPy scientific-computing workflows |
| How to open | Open it with NumPy `load` or another NPY-capable tool, then check dtype, shape, and format version. For large arrays, confirm that memory mapping works for the data layout and use case. | Open with NumPy `load` or an NPZ-capable tool, inspect the array names, and load what you need. Close the returned `NpzFile` when finished; check pickle settings for unfamiliar files that may contain object arrays. |
| Export or convert | Save with NumPy `save`. When converting from text, compare numeric types, byte order, shape, and missing-value handling. If object-dtype arrays are involved, determine whether pickle is required and do not enable it casually for untrusted files. | Save multiple arrays with `savez` or `savez_compressed`. Confirm whether entries are uncompressed or DEFLATE-compressed, and check array names, dtype, and shape with the receiving tool. Compare arrays and values after conversion. |
Choose by use case
Preserving dtype and multidimensional shape without text conversion
Saving one NumPy array in binary form with its type and shape · Passing arrays to NumPy-based scientific and machine-learning workflows
NPYMemory-mapping supported non-object arrays for access
Saving one NumPy array in binary form with its type and shape · Passing arrays to NumPy-based scientific and machine-learning workflows
NPYStoring several arrays in one file
Bundling multiple NumPy arrays in one ZIP archive · Passing named arrays between NumPy scientific-computing workflows
NPZChoosing uncompressed or compressed ZIP members as needed
Bundling multiple NumPy arrays in one ZIP archive · Passing named arrays between NumPy scientific-computing workflows
NPZKey point 1
The basic NPY unit is one array.
More on the differencesKey point 2
NPZ is an archive of per-array NPY members.
More on the differencesMore on the differences
Consider access patterns and compression cost, not only array count. Do not enable pickle for untrusted object-dtype input.
- savez writes an uncompressed archive; savez_compressed uses DEFLATE. The NPZ extension does not indicate compression.
- Numeric NPY data can be memory-mapped; object arrays cannot. Do not assume ordinary numpy.load memory-maps NPZ members in the same way.
Frequently asked questions
Is NPZ always smaller than NPY?
No. Contents, compression settings, and ZIP overhead matter. Measure size and loading time on real data.