Skip to main content

NDArray Methods

The NDArray class (from the default numpy-ts entry point) provides chainable instance methods that delegate to the corresponding standalone functions. Each method below calls its standalone equivalent under the hood.
These methods are only available on NDArray (the full entry point). NDArrayCore from numpy-ts/core does not include them. See the NDArray Class page for core methods available on both classes.

Arithmetic methods

add

Element-wise addition. See add.

subtract

Element-wise subtraction. See subtract.

multiply

Element-wise multiplication. See multiply.

divide

Element-wise division. See divide.

floor_divide

Element-wise floor division. See floor_divide.

mod

Element-wise modulo. See mod.

remainder

Element-wise remainder (same as mod). See remainder.

fmod

Element-wise C-style remainder. See fmod.

power

Raise elements to the given power. See power.

negative

Element-wise numerical negation (-x). See negative.

positive

Element-wise numerical positive (+x). Returns a copy. See positive.

absolute

Element-wise absolute value. See absolute.

reciprocal

Element-wise reciprocal (1/x). See reciprocal.

square

Element-wise square (x**2). See square.

sqrt

Element-wise square root. See sqrt.

cbrt

Element-wise cube root. See cbrt.

fabs

Element-wise absolute value (always returns float). See fabs.

sign

Element-wise sign indication (-1, 0, or 1). See sign.

heaviside

Heaviside step function. See heaviside.

divmod

Returns both floor quotient and remainder. See divmod.

Exponential and logarithmic methods

exp

Natural exponential (e^x). See exp.

exp2

Base-2 exponential (2^x). See exp2.

expm1

e^x - 1, accurate for small x. See expm1.

log

Natural logarithm. See log.

log2

Base-2 logarithm. See log2.

log10

Base-10 logarithm. See log10.

log1p

ln(1 + x), accurate for small x. See log1p.

logaddexp

log(exp(x1) + exp(x2)), numerically stable. See logaddexp.

logaddexp2

log2(2^x1 + 2^x2), numerically stable. See logaddexp2.

Trigonometric methods

sin

Sine (radians). See sin.

cos

Cosine (radians). See cos.

tan

Tangent (radians). See tan.

arcsin

Inverse sine. See arcsin.

arccos

Inverse cosine. See arccos.

arctan

Inverse tangent. See arctan.

arctan2

Element-wise arc tangent of this/other, choosing the correct quadrant. See arctan2.

hypot

Hypotenuse given two right-triangle legs. See hypot.

degrees

Convert radians to degrees. See degrees.

radians

Convert degrees to radians. See radians.

Hyperbolic methods

sinh

Hyperbolic sine. See sinh.

cosh

Hyperbolic cosine. See cosh.

tanh

Hyperbolic tangent. See tanh.

arcsinh

Inverse hyperbolic sine. See arcsinh.

arccosh

Inverse hyperbolic cosine. See arccosh.

arctanh

Inverse hyperbolic tangent. See arctanh.

Rounding methods

ceil

Ceiling of each element. See ceil.

floor

Floor of each element. See floor.

fix

Round towards zero. See fix.

rint

Round to nearest integer. See rint.

trunc

Truncate to integer part. See trunc.

around

Round to the given number of decimals (default: 0). See around.

round

Alias for around. See around.

clip

Clip values to [a_min, a_max]. Pass null for no bound on either side. See clip.

Comparison methods

equal

Element-wise equality. Returns boolean array. See equal.

not_equal

Element-wise inequality. Returns boolean array. See not_equal.

greater

Element-wise greater than. Returns boolean array. See greater.

greater_equal

Element-wise greater than or equal. Returns boolean array. See greater_equal.

less

Element-wise less than. Returns boolean array. See less.

less_equal

Element-wise less than or equal. Returns boolean array. See less_equal.

allclose

Returns true if all elements are equal within tolerance. Default rtol=1e-5, atol=1e-8. See allclose.

isclose

Element-wise comparison within tolerance. Returns boolean array. See isclose.

isnan

Test element-wise for NaN. Returns boolean array. See isnan.

isinf

Test element-wise for infinity. Returns boolean array. See isinf.

isfinite

Test element-wise for finiteness. Returns boolean array. See isfinite.

isnat

Test element-wise for NaT (Not a Time). Always returns false (no datetime support). See isnat.

Logic methods

logical_and

Element-wise logical AND. Returns boolean array. See logical_and.

logical_or

Element-wise logical OR. Returns boolean array. See logical_or.

logical_not

Element-wise logical NOT. Returns boolean array. See logical_not.

logical_xor

Element-wise logical XOR. Returns boolean array. See logical_xor.

invert

Bitwise NOT (alias for bitwise_not). See invert.

bitwise_and

Element-wise bitwise AND. Requires integer dtype. See bitwise_and.

bitwise_or

Element-wise bitwise OR. Requires integer dtype. See bitwise_or.

bitwise_xor

Element-wise bitwise XOR. Requires integer dtype. See bitwise_xor.

bitwise_not

Element-wise bitwise NOT. Requires integer dtype. See bitwise_not.

left_shift

Element-wise left bit shift. See left_shift.

right_shift

Element-wise right bit shift. See right_shift.

copysign

Change the sign of this to that of x2, element-wise. See copysign.

signbit

Returns true where the sign bit is set (negative). See signbit.

nextafter

Return the next floating-point value after this towards x2. See nextafter.

spacing

Return the distance between each element and the nearest adjacent number. See spacing.

Reduction methods

sum

Sum of elements along an axis. Returns a scalar when axis is undefined. See sum.

prod

Product of elements along an axis. See prod.

mean

Arithmetic mean along an axis. See mean.

std

Standard deviation along an axis. ddof defaults to 0. See std.

var

Variance along an axis. ddof defaults to 0. See var.

min

Minimum value along an axis. See min.

max

Maximum value along an axis. See max.

argmin

Index of the minimum value along an axis. See argmin.

argmax

Index of the maximum value along an axis. See argmax.

all

Test whether all elements evaluate to true. See all.

any

Test whether any element evaluates to true. See any.

ptp

Peak-to-peak (maximum minus minimum) along an axis. See ptp.

median

Median along an axis. See median.

percentile

Compute the q-th percentile (0—100). See percentile.

quantile

Compute the q-th quantile (0—1). See quantile.

average

Weighted average along an axis. See average.

cumsum

Cumulative sum along an axis. See cumsum.

cumprod

Cumulative product along an axis. See cumprod.

diff

Calculate the n-th discrete difference along an axis. See diff.

nansum

Sum treating NaNs as zero. See nansum.

nanprod

Product treating NaNs as one. See nanprod.

nanmean

Mean ignoring NaNs. See nanmean.

nanstd

Standard deviation ignoring NaNs. See nanstd.

nanvar

Variance ignoring NaNs. See nanvar.

nanmin

Minimum ignoring NaNs. See nanmin.

nanmax

Maximum ignoring NaNs. See nanmax.

nanargmin

Index of minimum ignoring NaNs. See nanargmin.

nanargmax

Index of maximum ignoring NaNs. See nanargmax.

nanmedian

Median ignoring NaNs. See nanmedian.

nancumsum

Cumulative sum treating NaNs as zero. See nancumsum.

nancumprod

Cumulative product treating NaNs as one. See nancumprod.

nanpercentile

Percentile ignoring NaNs. See nanpercentile.

nanquantile

Quantile ignoring NaNs. See nanquantile.

Shape methods

reshape

Return a new array with the given shape. Use -1 for one inferred dimension. See reshape.

flatten

Return a flattened copy (always 1D). See flatten.

ravel

Return a flattened array. Returns a view when possible, otherwise a copy. See ravel.

squeeze

Remove axes of length one. See squeeze.

expand_dims

Insert a new axis of length one at the given position. See expand_dims.

transpose

Permute the dimensions. With no arguments, reverses all axes. See transpose.

swapaxes

Interchange two axes. See swapaxes.

moveaxis

Move axes to new positions. See moveaxis.

T

Transpose property (no parentheses). Returns a view with reversed axes. See NDArray Class.

Linear algebra methods

dot

Dot product following NumPy semantics (inner product for 1D, matrix multiply for 2D). See dot.

matmul

Matrix multiplication (@ operator equivalent). See matmul.

inner

Inner product (contracts over last axes of both arrays). See inner.

outer

Outer product (flattens inputs, computes a[i] * b[j]). See outer.

tensordot

Tensor dot product along specified axes. Default contracts 2 axes. See tensordot.

trace

Sum of diagonal elements. See trace.

diagonal

Return specified diagonals. See diagonal.

Sorting and searching methods

sort

Return a sorted copy. Default sorts along the last axis. See sort.

argsort

Return indices that would sort the array. See argsort.

partition

Partially sort so that the element at kth position is in its final sorted position. See partition.

argpartition

Return indices that would partition the array. See argpartition.

searchsorted

Find indices where elements should be inserted to maintain order. See searchsorted.

nonzero

Return indices of non-zero elements, one array per dimension. See nonzero.

argwhere

Find indices of non-zero elements, returned as a 2D array of shape (N, ndim). See argwhere.

Indexing methods

take

Take elements along an axis. See take.

put

Set values at flat indices (in-place). See put.

choose

Construct an array by choosing from a list of arrays using this as the index. See choose.

compress

Return selected slices along an axis where condition is true. See compress.

repeat

Repeat elements of the array. See repeat.

resize

Return a new array with the given shape. Repeats data if the new shape is larger. See resize.

bindex

Boolean array indexing. Select elements where mask is true. See compress.

iindex

Integer array indexing (fancy indexing). Select elements by an array of indices. See take.

Complex number methods

conj

Return the complex conjugate, element-wise. For real arrays, returns a copy. See conj.

conjugate

Alias for conj. See conj.

Other methods

copy

Return a deep copy. See NDArray Class.

astype

Cast to a new dtype. See NDArray Class.

fill

Fill array in-place with a scalar. See NDArray Class.

toArray

Convert to nested JavaScript array. See NDArray Class.

tolist

Same as toArray. See NDArray Class.

tobytes

Serialize to raw bytes. See NDArray Class.

get

Get element by multi-dimensional indices. See NDArray Class.

set

Set element by multi-dimensional indices. See NDArray Class.

slice

NumPy-style string slicing. See NDArray Class.

row

Get row i. See NDArray Class.

col

Get column j. See NDArray Class.

rows

Get a range of rows. See NDArray Class.

cols

Get a range of columns. See NDArray Class.

item

Extract a scalar value. See NDArray Class.