.npy (single array) and .npz (multiple arrays, ZIP archive) binary formats. The API is split into two layers:
- Browser functions — Work with
ArrayBuffer/Uint8Array/ strings. Imported fromnumpy-tsornumpy-ts/core. - Node.js functions — Add file system I/O on top. Imported from
numpy-ts/node.
Browser API
These functions work in any JavaScript environment (browser, Deno, Bun, Node.js) since they operate on bytes, not files.parseNpy
Parse a.npy buffer into an NDArray.
Returns:
NDArray — The parsed array with correct shape, dtype, and data.
parseNpyHeader
Parse only the header of a.npy file without reading the data. Useful for inspecting file metadata.
Returns:
NpyHeader — Object with { descr, fortran_order, shape, version, headerLength }.
parseNpyData
Parse the data portion of a.npy file given pre-parsed metadata. Advanced use for custom streaming workflows.
Returns:
NDArray — The parsed array.
serializeNpy
Serialize an NDArray to.npy format bytes.
Returns:
Uint8Array — The .npy file as bytes, ready to be written or downloaded.
parseNpz / parseNpzSync
Parse a.npz buffer into a collection of named arrays. The async version supports DEFLATE-compressed files.
NpzParseOptions:
Returns:
NpzParseResult — { arrays: Map<string, NDArray>, skipped: string[], errors: Map<string, string> }.
serializeNpz / serializeNpzSync
Serialize multiple arrays to.npz format. The async version supports DEFLATE compression.
NpzSerializeOptions:
Returns:
Uint8Array (or Promise<Uint8Array>) — The .npz file as bytes.
loadNpz / loadNpzSync
Convenience wrappers that parse an.npz buffer and return a simple Record<string, NDArray> (discarding error/skip metadata).
Returns:
Record<string, NDArray> — Object mapping array names to NDArrays.
Node.js API
- Async
- Sync
load
Auto-detect file format (.npy or .npz) and load arrays from disk.Returns:
Promise<NDArray> for .npy files, Promise<NpzParseResult> for .npz files.save
Save a single NDArray to a.npy file.Returns:
Promise<void>savez
Save multiple arrays to an uncompressed.npz file.Returns:
Promise<void>savez_compressed
Save multiple arrays to a DEFLATE-compressed.npz file.Returns:
Promise<void>