NDArray Class
numpy-ts provides two array classes:NDArray— The full class with 100+ chainable instance methods. Returned by the defaultnumpy-tsentry point.NDArrayCore— The minimal class with only core properties and element access. Returned by the tree-shakeablenumpy-ts/coreentry point.
NDArray extends NDArrayCore. Every property and core method documented on this page exists on both classes.
Properties
shape
[3, 4].
ndim
shape.length.
size
dtype
'float64', 'float32', 'complex128', 'complex64', 'int64', 'int32', 'int16', 'int8', 'uint64', 'uint32', 'uint16', 'uint8', 'bool'.
data
TypedArray buffer holding the raw element data.
TypedArray is a union of Float64Array | Float32Array | BigInt64Array | Int32Array | Int16Array | Int8Array | BigUint64Array | Uint32Array | Uint16Array | Uint8Array.
strides
offset
The
offset property is accessed via the internal storage object (a.storage.offset). On NDArrayCore it is not directly exposed as a top-level property but can be read from the storage.base
base references the original array that owns the data. Returns null if the array owns its own data.
flags
T
transpose() with no arguments.
itemsize
nbytes
size * itemsize.
Core methods
copy
Returns:
NDArray — A new array with copied data.
astype
Returns:
NDArray — Array with the requested dtype.
fill
Returns:
void
toArray
Returns:
number | number[] | number[][] | ... — Nested JavaScript array matching the shape.
tolist
toArray().
Returns:
number | number[] | number[][] | ... — Same as toArray().
tobytes
ArrayBuffer. If the array is not C-contiguous, a contiguous copy is made first.
Returns:
ArrayBuffer — Raw byte representation.
get
Returns:
number | bigint | Complex — The scalar element value.
set
Returns:
void
slice
Returns:
NDArray — A view into the original array.
row
slice(String(i), ':').
Returns:
NDArray — The selected row as a view.
col
slice(':', String(j)).
Returns:
NDArray — The selected column as a view.
rows
Returns:
NDArray — View containing the selected rows.
cols
Returns:
NDArray — View containing the selected columns.
item
Returns:
number | bigint | Complex — The scalar value.
Bracket indexing ([])
All NDArray instances support bracket indexing via a transparent Proxy, providing natural JavaScript syntax for element access and slicing.
Static methods
NDArray.fromStorage
NDArray from an internal ArrayStorage object. This is primarily used internally by numpy-ts operations.
Returns:
NDArray — A new NDArray wrapping the given storage.