Skip to main content
numpy-ts provides NumPy-compatible text parsing and serialization, split into environment-agnostic buffer functions and file I/O functions. File I/O functions are available from the main numpy-ts entry point and work on Node.js, Bun, and Deno. They throw in browser environments.
The numpy-ts/node entry point is deprecated. Imports from it still work but you should migrate to numpy-ts.

Browser API

These functions work with strings and can be used in any JavaScript environment.

parseTxt

Parse a text string into an NDArray. Each row must have the same number of values.
Returns: NDArray — 2-D array (or 1-D if a single row/column).

serializeTxt

Serialize an NDArray to a text string.
Returns: string — Text representation of the array.

genfromtxt

Parse a text string with flexible handling of missing values. Replaces missing values with a fill value instead of throwing. This is a buffer-based function that works with strings in any environment.
Returns: NDArray — Parsed array with missing values filled in.

fromregex

Extract data from a text string using a regular expression with capture groups. This is a buffer-based function that works with strings in any environment.
Returns: NDArray — Array with one row per match and one column per capture group.

Options Reference

ParseTxtOptions

LoadTxtOptions

Alias for ParseTxtOptions. Used by loadtxt, genfromtxt, and their file-based variants.

SerializeTxtOptions

SaveTxtOptions

Alias for SerializeTxtOptions. Used by savetxt and its file-based variants.

File I/O API

loadtxt

Load data from a text file on disk.
Returns: Promise<NDArray> — The parsed array.

savetxt

Save an array to a text file.
Returns: Promise<void>

genfromtxtFile

Load and parse a text file from disk with flexible handling of missing values. This is the file-based equivalent of genfromtxt.
Returns: Promise<NDArray> — Parsed array with missing values filled in.

fromregexFile

Extract data from a text file on disk using a regular expression with capture groups. This is the file-based equivalent of fromregex.
Returns: Promise<NDArray>