NDArray

NDArray

The NDArray class

Constructor

new NDArray(data, options)

Source:
Parameters:
Name Type Description
data TypedArray

The underlying physical storage.

options Object
Properties
Name Type Attributes Default Description
shape Array | Int32Array

The dimensions of the array.

strides Array | Int32Array <optional>

The strides, defaults to C-style.

offset number <optional>
0

The view offset.

dtype string <optional>

The data type.

Classes

NDArray

Members

(static) optimize :NDWasmOptimize

Description:
  • Optimization module for linear programming, non-linear minimization, and linear regression.

Source:

Optimization module for linear programming, non-linear minimization, and linear regression.

Type:

Methods

abs() → {NDArray}

Description:
  • Returns a new array with the absolute value of each element.

Source:
Returns:
Type
NDArray

add(other) → {NDArray}

Description:
  • Element-wise addition. Supports broadcasting.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to add.

Returns:

A new array containing the results.

Type
NDArray

all() → {boolean}

Description:
  • Checks if all elements in the array are truthy.

Source:
Returns:
Type
boolean

any() → {boolean}

Description:
  • Checks if any element in the array is truthy.

Source:
Returns:
Type
boolean

argmax() → {number}

Description:
  • Returns the index of the maximum value in a flattened array.

Source:
Returns:
Type
number

argmin() → {number}

Description:
  • Returns the index of the minimum value in a flattened array.

Source:
Returns:
Type
number

argsort() → {NDArray}

Description:
  • Returns the indices that would sort the array. This is a wrapper around NDWasmAnalysis.argsort.

Source:
See:
Returns:

An array of indices.

Type
NDArray

asContiguous() → {NDArray}

Description:
  • Ensures the returned array has a contiguous memory layout. If the array is already contiguous, it returns itself. Otherwise, it returns a copy. Often used as a pre-processing step before calling WASM or other libraries.

Source:
Returns:

NDArray view.

Type
NDArray

bitwise_and(other) → {NDArray}

Description:
  • bitwise AND. Returns a new array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to perform the operation with.

Returns:
Type
NDArray

bitwise_lshift(other) → {NDArray}

Description:
  • bitwise lshift. Returns a new array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to perform the operation with.

Returns:
Type
NDArray

bitwise_not() → {NDArray}

Description:
  • bitwise NOT. Returns a new array.

Source:
Returns:
Type
NDArray

bitwise_or(other) → {NDArray}

Description:
  • bitwise OR. Returns a new array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to perform the operation with.

Returns:
Type
NDArray

bitwise_rshift(other) → {NDArray}

Description:
  • bitwise (logical) rshift. Returns a new array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to perform the operation with.

Returns:
Type
NDArray

bitwise_xor(other) → {NDArray}

Description:
  • bitwise XOR. Returns a new array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to perform the operation with.

Returns:
Type
NDArray

ceil() → {NDArray}

Description:
  • Returns a new array with the smallest integer greater than or equal to each element.

Source:
Returns:
Type
NDArray

cholesky() → {NDArray}

Description:
  • Computes the Cholesky decomposition. This is a wrapper around NDWasmDecomp.cholesky.

Source:
See:
Returns:

The lower triangular matrix L.

Type
NDArray

colview(j) → {NDArray}

Description:
  • Returns a 1D view of the j-th column. Only applicable to 2D arrays.

Source:
Parameters:
Name Type Description
j number

The column index.

Returns:

A 1D NDArray view.

Type
NDArray

cond(norm) → {number}

Description:
  • Estimates the reciprocal condition number of the matrix. This is a wrapper around NDWasmAnalysis.cond.

Source:
See:
Parameters:
Name Type Default Description
norm number 1

The norm type.

Returns:

The reciprocal condition number.

Type
number

conv2d(kernel, stride, padding) → {NDArray}

Description:
  • Performs 2D spatial convolution. This is a wrapper around NDWasmSignal.conv2d.

Source:
See:
Parameters:
Name Type Description
kernel NDArray

The convolution kernel.

stride number

The stride.

padding number

The padding.

Returns:

The convolved array.

Type
NDArray

copy(the) → {NDArray}

Description:
  • Returns a new, contiguous array with the same data. O(n) operation. This converts any view (transposed, sliced) into a new array with a standard C-style memory layout.

Source:
Parameters:
Name Type Description
the string | undefined

target dtype

Returns:

NDArray view.

Type
NDArray

correlate2d(kernel, stride, padding) → {NDArray}

Description:
  • Performs 2D spatial cross-correlation. This is a wrapper around NDWasmSignal.correlate2d.

Source:
See:
Parameters:
Name Type Description
kernel NDArray

The correlation kernel.

stride number

The stride.

padding number

The padding.

Returns:

The correlated array.

Type
NDArray

cos() → {NDArray}

Description:
  • Returns a new array with the cosine of each element.

Source:
Returns:
Type
NDArray

cov() → {NDArray}

Description:
  • Computes the covariance matrix. This is a wrapper around NDWasmAnalysis.cov.

Source:
See:
Returns:

The covariance matrix.

Type
NDArray

crossProduct(other) → {NDArray}

Description:
  • Cross Product. Only valid for 1D vectors of length 3.

Source:
Parameters:
Name Type Description
other NDArray
Returns:

New NDArray of size 3.

Type
NDArray

cumprod(axisopt) → {NDArray|number}

Description:
  • Computes the cumprod of elements along the specified axis.

Source:
Parameters:
Name Type Attributes Default Description
axis number | null <optional>
null
Returns:
Type
NDArray | number

dct() → {NDArray}

Description:
  • Computes the 1D Discrete Cosine Transform. This is a wrapper around NDWasmSignal.dct.

Source:
See:
Returns:

The result of the DCT.

Type
NDArray

div(other) → {NDArray}

Description:
  • Element-wise division. Supports broadcasting.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to divide by.

Returns:

A new array containing the results.

Type
NDArray

dotProduct(other) → {number}

Description:
  • Dot Product (Scalar Inner Product). Supports 1D arrays (vectors) only.

Source:
Parameters:
Name Type Description
other NDArray
Returns:

Scalar result.

Type
number

eigen() → {Object}

Description:
  • Computes the eigenvalues and eigenvectors of a general square matrix.

Source:
See:
Returns:

An object containing eigenvalues and eigenvectors.

Type
Object

eigenSym(vectors) → {Object}

Description:
  • Computes the eigenvalue decomposition for a symmetric matrix. This is a wrapper around NDWasmAnalysis.eigenSym.

Source:
See:
Parameters:
Name Type Description
vectors boolean

Whether to compute the eigenvectors.

Returns:

An object containing the eigenvalues and eigenvectors.

Type
Object

eq(other) → {NDArray}

Description:
  • Element-wise equality comparison. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to compare with.

Returns:
Type
NDArray

exp() → {NDArray}

Description:
  • Returns a new array with e raised to the power of each element.

Source:
Returns:
Type
NDArray

fft() → {NDArray}

Description:
  • Computes the 1D Fast Fourier Transform. This is a wrapper around NDWasmSignal.fft.

Source:
See:
This:
Returns:

Complex result with shape [..., 2].

Type
NDArray

fft2() → {NDArray}

Description:
  • Computes the 2D Fast Fourier Transform. The input array must be 3D with shape [rows, cols, 2]. This is a wrapper around NDWasmSignal.fft2.

Source:
See:
Returns:

2D Complex result, with the same shape as input.

Type
NDArray

filter(predicateOrMask) → {NDArray}

Description:
  • Responsibility: Implements element-wise filtering. Returns a NEW 1D contiguous NDArray (Copy). Filters elements based on a predicate function or a boolean mask.

Source:
Parameters:
Name Type Description
predicateOrMask function | Array | NDArray

A function returning boolean, or an array/NDArray of the same shape/size containing truthy/falsy values.

Returns:

A new 1D NDArray containing the matched elements.

Type
NDArray

flatten() → {NDArray}

Source:
Returns:
  • new flatten view to the array
Type
NDArray

floor() → {NDArray}

Description:
  • Returns a new array with the largest integer less than or equal to each element.

Source:
Returns:
Type
NDArray

ger(other) → {NDArray}

Description:
  • Computes the vector outer product. This is a wrapper around NDWasmBlas.ger.

Source:
See:
Parameters:
Name Type Description
other NDArray

The other vector.

Returns:

The resulting matrix.

Type
NDArray

get(…indices) → {number}

Description:
  • Gets a single element from the array. Note: This has higher overhead than batch operations. Use with care in performance-critical code.

Source:
Parameters:
Name Type Attributes Description
indices number <repeatable>

The indices of the element to get.

Returns:
Type
number

gt(other) → {NDArray}

Description:
  • Element-wise greater-than comparison. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to compare with.

Returns:
Type
NDArray

gte(other) → {NDArray}

Description:
  • Element-wise greater-than-or-equal comparison. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to compare with.

Returns:
Type
NDArray

iadd(other) → {NDArray}

Description:
  • In-place element-wise addition.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to add.

Returns:

The modified array (this).

Type
NDArray

idiv(other) → {NDArray}

Description:
  • In-place element-wise division.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to divide by.

Returns:

The modified array (this).

Type
NDArray

ifft() → {NDArray}

Description:
  • Computes the 1D Inverse Fast Fourier Transform. This is a wrapper around NDWasmSignal.ifft.

Source:
See:
This:
Returns:

Complex result with shape [..., 2].

Type
NDArray

ifft2() → {NDArray}

Description:
  • 2D Inverse Complex-to-Complex Fast Fourier Transform. The input array must be 3D with shape [rows, cols, 2]. The transform is performed in-place. This is a wrapper around NDWasmSignal.ifft2.

Source:
See:
Returns:

2D Complex result, with the same shape as input.

Type
NDArray

imod(other) → {NDArray}

Description:
  • In-place element-wise modulo.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar divisor.

Returns:

The modified array (this).

Type
NDArray

imul(other) → {NDArray}

Description:
  • In-place element-wise multiplication.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to multiply by.

Returns:

The modified array (this).

Type
NDArray

inv() → {NDArray}

Description:
  • Computes the multiplicative inverse of the matrix. This is a wrapper around NDWasmDecomp.inv.

Source:
See:
Returns:

The inverted matrix.

Type
NDArray

ipow(other) → {NDArray}

Description:
  • In-place element-wise exponentiation.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar exponent.

Returns:

The modified array (this).

Type
NDArray

isub(other) → {NDArray}

Description:
  • In-place element-wise subtraction.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to subtract.

Returns:

The modified array (this).

Type
NDArray

iterate(callback)

Description:
  • Generic iterator that handles stride logic. It's slow. use map if you want to use jit.

Source:
See:
Parameters:
Name Type Description
callback function

A function called with (value, index, flatPhysicalIndex).

jsMatMul(other) → {NDArray}

Description:
  • Matrix Multiplication in js. Operations: (M, K) @ (K, N) -> (M, N)

Source:
Parameters:
Name Type Description
other NDArray
Returns:

New NDArray.

Type
NDArray

jsMatVecMul(vec) → {NDArray}

Description:
  • Matrix-Vector Multiplication in js. Operation: (M, K) @ (K,) -> (M,)

Source:
Parameters:
Name Type Description
vec NDArray
Returns:

New NDArray (Vector).

Type
NDArray

kmeans(k, maxIter) → {Object}

Description:
  • Performs K-Means clustering. This is a wrapper around NDWasmAnalysis.kmeans.

Source:
See:
Parameters:
Name Type Description
k number

The number of clusters.

maxIter number

The maximum number of iterations.

Returns:

An object containing the centroids, labels, and number of iterations.

Type
Object

kronecker(other) → {NDArray}

Description:
  • Computes the Kronecker product. This is a wrapper around NDWasmAnalysis.kronecker.

Source:
See:
Parameters:
Name Type Description
other NDArray

The other matrix.

Returns:

The result of the Kronecker product.

Type
NDArray

log() → {NDArray}

Description:
  • Returns a new array with the natural logarithm (base e) of each element.

Source:
Returns:
Type
NDArray

logical_and(other) → {NDArray}

Description:
  • Element-wise logical AND. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to perform the operation with.

Returns:
Type
NDArray

logical_not() → {NDArray}

Description:
  • Element-wise logical NOT. Returns a new boolean (uint8) array.

Source:
Returns:
Type
NDArray

logical_or(other) → {NDArray}

Description:
  • Element-wise logical OR. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to perform the operation with.

Returns:
Type
NDArray

lt(other) → {NDArray}

Description:
  • Element-wise less-than comparison. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to compare with.

Returns:
Type
NDArray

lte(other) → {NDArray}

Description:
  • Element-wise less-than-or-equal comparison. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to compare with.

Returns:
Type
NDArray

lu() → {NDArray}

Description:
  • Computes the LU decomposition. This is a wrapper around NDWasmDecomp.lu.

Source:
See:
Returns:

The LU matrix.

Type
NDArray

map(fnOrStr) → {NDArray}

Description:
  • High-performance element-wise mapping with jit compilation.

Source:
Parameters:
Name Type Description
fnOrStr string | function

The function string to apply to each element, like 'Math.sqrt(${val})', or a lambda expression

Returns:

A new array with the results.

Type
NDArray

matMul(other) → {NDArray}

Description:
  • Performs matrix multiplication. This is a wrapper around NDWasmBlas.matMul.

Source:
See:
Parameters:
Name Type Description
other NDArray

The right-hand side matrix.

Returns:

The result of the matrix multiplication.

Type
NDArray

matMulBatch(other) → {NDArray}

Description:
  • Performs batched matrix multiplication. This is a wrapper around NDWasmBlas.matMulBatch.

Source:
See:
Parameters:
Name Type Description
other NDArray

The right-hand side batch of matrices.

Returns:

The result of the batched matrix multiplication.

Type
NDArray

matPow(k) → {NDArray}

Description:
  • Computes the matrix power. This is a wrapper around NDWasmBlas.matPow.

Source:
See:
Parameters:
Name Type Description
k number

The exponent.

Returns:

The result of the matrix power.

Type
NDArray

matVecMul(vec) → {NDArray}

Description:
  • Performs matrix-vector multiplication. This is a wrapper around NDWasmBlas.matVecMul.

Source:
See:
Parameters:
Name Type Description
vec NDArray

The vector to multiply by.

Returns:

The resulting vector.

Type
NDArray

max(axisopt) → {NDArray|number}

Description:
  • Returns the maximum value along the specified axis.

Source:
Parameters:
Name Type Attributes Default Description
axis number | null <optional>
null
Returns:
Type
NDArray | number

mean(axisopt) → {NDArray|number}

Description:
  • Computes the arithmetic mean along the specified axis.

Source:
Parameters:
Name Type Attributes Default Description
axis number | null <optional>
null
Returns:
Type
NDArray | number

min(axisopt) → {NDArray|number}

Description:
  • Returns the minimum value along the specified axis.

Source:
Parameters:
Name Type Attributes Default Description
axis number | null <optional>
null
Returns:
Type
NDArray | number

mod(other) → {NDArray}

Description:
  • Element-wise modulo. Supports broadcasting.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar divisor.

Returns:

A new array containing the results.

Type
NDArray

mul(other) → {NDArray}

Description:
  • Element-wise multiplication. Supports broadcasting.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to multiply by.

Returns:

A new array containing the results.

Type
NDArray

neg() → {NDArray}

Description:
  • Returns a new array with the numeric negation of each element.

Source:
Returns:
Type
NDArray

neq(other) → {NDArray}

Description:
  • Element-wise inequality comparison. Returns a new boolean (uint8) array.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to compare with.

Returns:
Type
NDArray

norm(type) → {number}

Description:
  • Computes the matrix norm. This is a wrapper around NDWasmAnalysis.norm.

Source:
See:
Parameters:
Name Type Description
type number

The type of norm to compute.

Returns:

The norm of the matrix.

Type
number

pairwiseDist(other) → {NDArray}

Description:
  • Computes the pairwise distances between two sets of vectors. This is a wrapper around NDWasmAnalysis.pairwiseDist.

Source:
See:
Parameters:
Name Type Description
other NDArray

The other set of vectors.

Returns:

The distance matrix.

Type
NDArray

pick(…specs)

Description:
  • Advanced Indexing (Fancy Indexing). Returns a physical COPY of the selected data using a JIT-compiled engine. Picks elements along each dimension. Note: unlike numpy, for advanced (fancy) indexing, output shape won't be reordered. Dim for 1-element advanced indexing won't be removed, either.

Source:
Parameters:
Name Type Attributes Description
specs Array.<number> | TypedArray | number | null | undefined <repeatable>

Index selectors. null/undefined means select all

pinv() → {NDArray}

Description:
  • Computes the Moore-Penrose pseudo-inverse of the matrix. This is a wrapper around NDWasmDecomp.pinv.

Source:
See:
Returns:

The pseudo-inverted matrix.

Type
NDArray

pow(other) → {NDArray}

Description:
  • Element-wise exponentiation. Supports broadcasting.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar exponent.

Returns:

A new array containing the results.

Type
NDArray

push() → {NDWasmArray}

Description:
  • push to wasm

Source:
Returns:
Type
NDWasmArray

qr() → {Object}

Description:
  • Computes the QR decomposition. This is a wrapper around NDWasmDecomp.qr.

Source:
See:
Returns:

An object containing the Q and R matrices.

Type
Object

rank(tol) → {number}

Description:
  • Computes the rank of the matrix. This is a wrapper around NDWasmAnalysis.rank.

Source:
See:
Parameters:
Name Type Description
tol number

The tolerance for singular values.

Returns:

The rank of the matrix.

Type
number

reshape(…newShape) → {NDArray}

Description:
  • Returns a new array with a new shape, without changing data. O(1) operation. This only works for contiguous arrays. If the array is not contiguous, you must call .copy() first.

Source:
Parameters:
Name Type Attributes Description
newShape number <repeatable>

The new shape.

Returns:

NDArray view.

Type
NDArray

rfft() → {NDArray}

Description:
  • Computes the 1D Real-to-Complex Fast Fourier Transform. This is a wrapper around NDWasmSignal.rfft.

Source:
See:
This:
Returns:

Complex result with shape [..., 2].

Type
NDArray

rifft(n) → {NDArray}

Description:
  • 1D Complex-to-Real Inverse Fast Fourier Transform. The input must be a complex array of shape [k, 2], where k is n/2 + 1. This is a wrapper around NDWasmSignal.rifft.

Source:
See:
This:
Parameters:
Name Type Description
n number

Length of the original real signal.

Returns:

Real-valued time domain signal.

Type
NDArray

round() → {NDArray}

Description:
  • Returns a new array with the value of each element rounded to the nearest integer.

Source:
Returns:
Type
NDArray

rowview(i) → {NDArray}

Description:
  • Returns a 1D view of the i-th row. Only applicable to 2D arrays.

Source:
Parameters:
Name Type Description
i number

The row index.

Returns:

A 1D NDArray view.

Type
NDArray

set(value, …indices) → {NDArray}

Description:
  • Sets value(s) in the array using a unified, JIT-optimized engine. Supports scalar indexing, fancy (array) indexing, and NumPy-style broadcasting.

Source:
Parameters:
Name Type Attributes Description
value number | Array | NDArray

The source data to assign.

indices number | Array | null <repeatable>

Indices for each dimension.

Returns:
Type
NDArray

sin() → {NDArray}

Description:
  • Returns a new array with the sine of each element.

Source:
Returns:
Type
NDArray

slice(…specs) → {NDArray}

Description:
  • Returns a new view of the array sliced along each dimension. This implementation strictly follows NumPy's basic slicing logic.

Source:
Parameters:
Name Type Attributes Description
specs Array | number | null | undefined <repeatable>

Slice parameters for each dimension.

  • number: Scalar indexing. Picks a single element and reduces dimensionality (e.g., arr[0]).
  • [start, end, step]: Range slicing (e.g., arr[start:end:step]).
  • []/null/undefined: Selects the entire dimension (e.g., arr[:]).
Throws:

If a scalar index is out of bounds or step is zero.

Type
Error
Returns:

A new O(1) view of the underlying data.

Type
NDArray

solve(b) → {NDArray}

Description:
  • Solves a system of linear equations. This is a wrapper around NDWasmDecomp.solve.

Source:
See:
Parameters:
Name Type Description
b NDArray

The right-hand side matrix or vector.

Returns:

The solution matrix.

Type
NDArray

sqrt() → {NDArray}

Description:
  • Returns a new array with the square root of each element.

Source:
Returns:
Type
NDArray

squeeze(axis) → {NDArray}

Description:
  • Remove axes of length one from the shape. O(1) operation.

Source:
Parameters:
Name Type Default Description
axis number | null null

The axis to squeeze. If null, all axes of length 1 are removed.

Returns:

NDArray view.

Type
NDArray

std(axisopt) → {NDArray|number}

Description:
  • Computes the standard deviation along the specified axis.

Source:
Parameters:
Name Type Attributes Default Description
axis number | null <optional>
null

The axis to reduce.

Returns:
Type
NDArray | number

sub(other) → {NDArray}

Description:
  • Element-wise subtraction. Supports broadcasting.

Source:
Parameters:
Name Type Description
other NDArray | number

The array or scalar to subtract.

Returns:

A new array containing the results.

Type
NDArray

sum(axisopt) → {NDArray|number}

Description:
  • Computes the sum of elements along the specified axis.

Source:
Parameters:
Name Type Attributes Default Description
axis number | null <optional>
null
Returns:
Type
NDArray | number

svd() → {Object}

Description:
  • Computes the Singular Value Decomposition (SVD). This is a wrapper around NDWasmDecomp.svd.

Source:
See:
Returns:

An object containing the U, S, and V matrices.

Type
Object

syrk() → {NDArray}

Description:
  • Performs a symmetric rank-k update. This is a wrapper around NDWasmBlas.syrk.

Source:
See:
Returns:

The resulting symmetric matrix.

Type
NDArray

tan() → {NDArray}

Description:
  • Returns a new array with the tangent of each element.

Source:
Returns:
Type
NDArray

toArray() → {Array|number}

Description:
  • To JavaScript Array

Source:
Returns:

the array

Type
Array | number

toString() → {String}

Description:
  • Returns a string representation of the ndarray. Formats high-dimensional data with proper indentation and line breaks.

Source:
Returns:
Type
String

toWasm(runtime) → {WasmBuffer}

Description:
  • Projects the current ndarray to a WASM proxy (WasmBuffer).

Source:
Parameters:
Name Type Description
runtime WasmRuntime
Returns:

A WasmBuffer instance representing the NDArray in WASM memory.

Type
WasmBuffer

topk(k, largest) → {Object}

Description:
  • Finds the top K largest or smallest elements. This is a wrapper around NDWasmAnalysis.topk.

Source:
See:
Parameters:
Name Type Description
k number

The number of elements to find.

largest boolean

Whether to find the largest or smallest elements.

Returns:

An object containing the values and indices of the top K elements.

Type
Object

trace() → {number}

Description:
  • Calculates the trace of a 2D square matrix (sum of diagonal elements). Complexity: O(n)

Source:
Throws:

If the array is not 2D or not a square matrix.

Type
Error
Returns:

The sum of the diagonal elements.

Type
number

transpose(…axes) → {NDArray}

Description:
  • Returns a new view of the array with axes transposed. O(1) operation.

Source:
Parameters:
Name Type Attributes Description
axes number <repeatable>

The new order of axes, e.g., [1, 0] for a matrix transpose. If not specified, reverses the order of the axes.

Returns:

NDArray view.

Type
NDArray

var(axisopt) → {NDArray|number}

Description:
  • Computes the variance along the specified axis. Note: This implementation uses a two-pass approach (mean first, then squared differences). Ensure that the sub method supports broadcasting if axis is not null.

Source:
Parameters:
Name Type Attributes Default Description
axis number | null <optional>
null

The axis to reduce.

Returns:
Type
NDArray | number