The NDArray
Every value in numpy-ts is anNDArray — a multidimensional, homogeneously-typed array backed by a JavaScript TypedArray. If you have used NumPy in Python, you already know the mental model: shape, dtype, strides, and element-wise operations.
Creating arrays from JavaScript data
Usearray() to create an NDArray from nested JavaScript arrays or a flat list:
NDArray properties
Every NDArray exposes the same set of descriptive properties you would find in NumPy:| Property | Type | Description |
|---|---|---|
shape | readonly number[] | Length of each dimension |
ndim | number | Number of dimensions (shape.length) |
size | number | Total element count |
dtype | string | Element data type (e.g. 'float64') |
data | TypedArray | Underlying typed array buffer |
strides | readonly number[] | Elements to skip per dimension |
itemsize | number | Bytes per element |
nbytes | number | Total bytes (size * itemsize) |
base | NDArray | null | Parent array if this is a view, else null |
flags | object | C_CONTIGUOUS, F_CONTIGUOUS, OWNDATA |
T | NDArray | Transposed view (shorthand for .transpose()) |
The T property — transposing
The T property returns a transposed view of the array. No data is copied; the view shares the same underlying buffer:
T returns a view, modifying the transpose also modifies the original:
Flags and views
Theflags property tells you about the memory layout:
base property indicates whether an array is a view of another array:
Inspecting arrays
toString()
Returns a summary string with shape and dtype:
array2string()
For NumPy-style formatted output, use the array2string function:
array_repr() and array_str()
Converting back to JavaScript
toArray()
Converts the NDArray into a nested JavaScript array matching the shape:
tolist()
Alias for toArray(). Provided for NumPy API compatibility:
item()
Extract a single scalar from a size-1 array:
Accessing the raw typed array
Thedata property gives you direct access to the underlying TypedArray:
Iteration
NDArrays implement the JavaScript iterator protocol. For 1-D arrays, iteration yields elements. For N-D arrays, it yields (N-1)-D sub-arrays along the first axis:Method chaining
The full entry point (numpy-ts) returns NDArray objects that support method chaining, letting you write expressive pipelines:
If bundle size matters more than method chaining, use
numpy-ts/core instead. See the Installation guide for details.Next steps
Data Types
Understand the 13 supported dtypes and type promotion rules.
Slicing & Indexing
Select sub-arrays, rows, columns, and individual elements.