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.| Name | Type | Default | Description |
|---|---|---|---|
text | string | — | The text content to parse. |
options | ParseTxtOptions | {} | Parsing options (see table below). |
NDArray — 2-D array (or 1-D if a single row/column).
serializeTxt
Serialize an NDArray to a text string.| Name | Type | Default | Description |
|---|---|---|---|
arr | NDArray | — | Array to serialize (must be 1-D or 2-D). |
options | SerializeTxtOptions | {} | Serialization options (see table below). |
string — Text representation of the array.
genfromtxt
Parse a text file with more flexible handling of missing values. Replaces missing values with a fill value instead of throwing.| Name | Type | Default | Description |
|---|---|---|---|
path | string | — | Path to the text file to parse. |
options | LoadTxtOptions | {} | Parsing options. Use missing_values and filling_values to handle gaps. |
NDArray — Parsed array with missing values filled in.
fromregex
Extract data from a text file using a regular expression with capture groups.| Name | Type | Default | Description |
|---|---|---|---|
path | string | — | Path to the text file to search. |
regexp | RegExp | string | — | Regular expression with capture groups. Each match produces one row; each group produces one column. |
dtype | DType | 'float64' | Data type of the resulting array. |
NDArray — Array with one row per match and one column per capture group.
Options Reference
ParseTxtOptions
| Name | Type | Default | Description |
|---|---|---|---|
delimiter | string | whitespace | String used to separate values. By default, any consecutive whitespace acts as delimiter. |
comments | string | '#' | Character indicating the start of a comment line. |
skiprows | number | 0 | Number of lines to skip at the beginning of the file. |
usecols | number | number[] | all | Which columns to read (0-indexed). |
max_rows | number | all | Maximum number of data rows to read (after skiprows). |
dtype | DType | 'float64' | Data type of the resulting array. |
encoding | string | 'utf-8' | Character encoding (only relevant for Node.js file operations). |
missing_values | string | string[] | undefined | String representation(s) of missing values (used by genfromtxt). |
filling_values | number | NaN (float) / 0 (int) | Replacement value for missing entries. |
SerializeTxtOptions
| Name | Type | Default | Description |
|---|---|---|---|
fmt | string | '%.18e' | Printf-style format string. Examples: '%.6f' (6 decimals), '%.2e' (scientific), '%d' (integer). |
delimiter | string | ' ' | String separating columns. |
newline | string | '\n' | String written at the end of each row. |
header | string | undefined | Text written at the beginning of the file. Automatically prefixed with the comment character. |
footer | string | undefined | Text written at the end of the file. |
comments | string | '# ' | String prepended to header and footer lines. |
Node.js API
- Async
- Sync
loadtxt
Load data from a text file on disk.| Name | Type | Default | Description |
|---|---|---|---|
path | string | — | Path to the text file. |
options | LoadTxtOptions | {} | Parsing options. |
Promise<NDArray> — The parsed array.savetxt
Save an array to a text file.| Name | Type | Default | Description |
|---|---|---|---|
path | string | — | Output file path. |
arr | NDArray | — | Array to save (must be 1-D or 2-D). |
options | SaveTxtOptions | {} | Serialization options. |
Promise<void>