Every value in numpy-ts is an NDArray — 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.
Every NDArray exposes the same set of descriptive properties you would find in NumPy:
const a = np.array([[1, 2, 3], [4, 5, 6]]);a.shape; // [2, 3] -- dimensions of the arraya.ndim; // 2 -- number of dimensionsa.size; // 6 -- total number of elementsa.dtype; // 'float64' -- data type of the elementsa.strides; // [3, 1] -- step sizes to traverse each dimensiona.itemsize; // 8 -- size of one element in bytesa.nbytes; // 48 -- total bytes consumed (size * itemsize)
The data property gives you direct access to the underlying TypedArray:
const a = np.array([1, 2, 3], { dtype: 'float32' });a.data; // Float32Array [1, 2, 3]a.data.buffer; // The underlying ArrayBuffer
Modifying data directly bypasses numpy-ts and can lead to unexpected behavior, especially with non-contiguous views. Use get() / set() or operations instead.
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:
const a = np.array([10, 20, 30]);for (const val of a) { console.log(val); // 10, 20, 30}const m = np.array([[1, 2], [3, 4]]);for (const row of m) { console.log(row.toArray()); // [1, 2] then [3, 4]}
The full entry point (numpy-ts) returns NDArray objects that support method chaining, letting you write expressive pipelines:
import * as np from 'numpy-ts';const result = np.array([1, 2, 3, 4, 5, 6]) .reshape(2, 3) // shape [2, 3] .add(10) // add 10 to every element .T // transpose to [3, 2] .sum(1); // sum along axis 1console.log(result); // array with 3 elements
If bundle size matters more than method chaining, use numpy-ts/core instead. See the Installation guide for details.