Skip to main content
numpy-ts supports the same file formats as NumPy: .npy (single array), .npz (multiple arrays), and delimited text files. All functions are available from the main numpy-ts entry point.
File-based functions read and write files on disk and require a server runtime (Node.js, Bun, or Deno). In the browser, they throw: “File IO requires Node.js, Bun, or Deno. In the browser, use parseNpy(buffer) / parseTxt(text) with fetch() instead.” Buffer-based functions work with ArrayBuffer, Uint8Array, and strings in all environments.
numpy-ts/node still works but is a deprecated alias for numpy-ts. Update your imports to from 'numpy-ts'.

NPY files (single array)

The .npy format stores a single array with its dtype and shape metadata.
Synchronous variants are also available:

NPZ archives (multiple arrays)

The .npz format stores multiple named arrays in a single ZIP archive. savez_compressed applies deflate compression.

Text files

Load and save delimited text files such as CSV and TSV.

Flexible text loading

genfromtxt

Like loadtxt, but handles missing values more gracefully.

fromregex

Extract numeric data from unstructured text using regular expressions.

Types

File I/O functions accept typed options objects:

Sync I/O internals

Sync file I/O functions (loadSync, saveSync, loadNpySync, etc.) use an async self-warming cache that resolves node:fs at module load time. This is transparent in practice. In the extremely unlikely case that you call a sync function before the microtask queue has flushed, call any async I/O function first to ensure the cache is ready.

NumPy compatibility

Files saved by numpy-ts can be loaded by Python NumPy, and vice versa:
numpy-ts does not support NumPy object arrays, structured arrays, or pickle-based .npy files. Only numeric dtypes (float16, float64, float32, int32, int16, int8, uint32, uint16, uint8, bool, complex128, complex64) are supported.