Cyforanumera
npm

API reference

Math (ufuncs)

Element-wise functions with NumPy broadcasting and type promotion. Operands can be NDArrays, nested arrays or scalars. JS scalars are "weak", so int32 array + 1 stays int32. Pass { out } to write into an existing array (NumPy out=): the result is cast to out.dtype under same_kind, and out itself is returned.

NameSummary
np.addElement-wise +, -, *, /.
np.floorDividePython-style floor division and modulo: the result of mod takes the sign of the divisor.
np.powerElement-wise a ** b.
np.absAbsolute value and negation.
np.realComplex helpers.
np.sqrtSquare root, e^x and the natural log.
np.matmulMatrix product (@), with batched broadcasting over leading axes.
np.outerOuter product of two vectors (flattened), and the inner product over the last axes.
np.sinElement-wise trigonometric functions and their inverses, in radians.
np.sinhElement-wise hyperbolic functions and their inverses, with complex loops.
np.arctan2arctan2 is the quadrant-aware angle of the point (x, y); hypot is sqrt(a² + b²) without intermediate overflow.
np.deg2radAngle conversion.
np.exp22**x, exp(x) - 1, base-2 / base-10 logarithms and log(1 + x).
np.logaddexplog(exp(a) + exp(b)) and log2(2**a + 2**b) without overflow.
np.cbrtCube root (real only); x*x and 1/x, which keep integer dtypes (integer reciprocal truncates, bool uses int8).
np.floorRound down, up, toward zero (fix is the same as trunc) and to the nearest even integer.
np.roundRound half to even to decimals places; negative decimals round to tens, hundreds, ….
np.positiveElement-wise +x (a copy).
np.fmodfmod is the C remainder: the result takes the sign of the dividend (unlike mod/remainder, which follow the divisor).
np.floatPowerElement-wise a ** b computed in float64 (or complex128), so integer inputs can take negative exponents.
np.signsign gives -1, 0 or 1 (NaN stays NaN; complex z/|z|).
np.maximumElement-wise maximum/minimum.
np.clipLimit values to [min, max]; null skips a side.
np.copysignFloating-point bit helpers: magnitude of a with the sign of b; the next representable value after a toward b; the gap to the next value away from zero; whether the sign bit is set (bool result, true for -0).
np.ldexpx * 2**n for an integer exponent array n (non-integer or uint64 exponents raise DTypeError, as in NumPy).
np.gcdGreatest common divisor and least common multiple of integers (results are non-negative).
np.divmodTwo-output ufuncs returning [NDArray, NDArray].
np.i0i0 is the modified Bessel function of the first kind, order 0 (real input; float16/float32 kept, otherwise float64).
np.nanToNumReplace NaN with nan (default 0) and ±Infinity with posinf/neginf (default: the dtype's largest finite values).
np.realIfCloseReturn the real part when every imaginary part is below tol (counted in machine epsilons when tol > 1); otherwise return x unchanged.
np.unwrapRemove jumps between neighbours larger than discont (default period / 2) by adding multiples of period.

np.add

#
np.add(a, b, { out? }) · np.subtract · np.multiply · np.divide

Element-wise +, -, *, /. divide is true division, so integer inputs give float64.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.add([[1], [2]], [10, 20]); // => [[11, 21], [12, 22]]
np.subtract([5, 7], 2);       // => [3, 5]
np.multiply([1, 2, 3], 2);    // => [2, 4, 6]
np.divide([1, 3], 2);         // => [0.5, 1.5]
TypeScript declaration
np.add(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.subtract(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.multiply(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.divide(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.floorDivide

#
np.floorDivide(a, b, { out? }) · np.mod(a, b, { out? })

Python-style floor division and modulo: the result of mod takes the sign of the divisor.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.floorDivide([7, -7], 2); // => [3, -4]
np.mod([7, -7], 3);         // => [1, 2]
TypeScript declaration
np.floorDivide(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.mod(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.power

#
np.power(a, b, { out? })

Element-wise a ** b.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.power([1, 2, 3], 2);  // => [1, 4, 9]
np.power(2, [0.5, -1]).toArray()[1]; // => 0.5
TypeScript declaration
np.power(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.abs

#
np.abs(a, { out? }) · np.negative(a, { out? })

Absolute value and negation. For complex input abs returns the magnitude in the matching real dtype (complex128 → float64).

Parameters

aArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.abs([-1, 2, -3]);  // => [1, 2, 3]
np.negative([1, -2]); // => [-1, 2]
np.abs([np.complex(3, 4)]); // => [5]
TypeScript declaration
np.abs(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.negative(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.real

#
np.real(a) · np.imag(a) · np.conj(a) · np.conjugate(a) · np.angle(z, deg?) · np.iscomplex(a) · np.isreal(a) · np.iscomplexobj(a) · np.isrealobj(a)

Complex helpers. real and imag return views of the components (also available as a.real and a.imag), so writing to them changes a. For real input, real is a itself and imag is read-only zeros. conj negates the imaginary part. angle is atan2(im, re), in degrees if deg is true. iscomplex and isreal test imag != 0 element by element. iscomplexobj and isrealobj test the dtype.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
[deg]boolean
angle only: return degrees. Default false.

Returns

NDArray (boolean for iscomplexobj / isrealobj)

Example

TypeScript
const z = np.array([np.complex(1, 2), np.complex(3, -4)]);
np.real(z);     // => [1, 3]
np.imag(z);     // => [2, -4]
np.imag(np.conj(z)); // => [-2, 4]
np.angle([np.complex(0, 1)], true); // => [90]
np.iscomplex([np.complex(1, 0), np.complex(1, 1)]); // => [false, true]
np.isreal([1, 2]);     // => [true, true]
np.iscomplexobj(z);    // => true
np.isrealobj([1, 2]);  // => true
TypeScript declaration
np.real(a: ArrayLike): NDArray
np.imag(a: ArrayLike): NDArray
np.conj(a: ArrayLike): NDArray
np.conjugate(a: ArrayLike): NDArray
np.angle(z: ArrayLike, deg?: boolean | undefined): NDArray
np.iscomplex(a: ArrayLike): NDArray
np.isreal(a: ArrayLike): NDArray
np.iscomplexobj(a: ArrayLike): boolean
np.isrealobj(a: ArrayLike): boolean

np.sqrt

#
np.sqrt(a, { out? }) · np.exp(a, { out? }) · np.log(a, { out? })

Square root, e^x and the natural log. Integer inputs are promoted to float64; out-of-domain inputs give NaN, as in NumPy.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.sqrt([4, 9]);    // => [2, 3]
np.exp([0]);        // => [1]
np.log([1]);        // => [0]
Number.isNaN(np.sqrt(-1).item()); // => true
TypeScript declaration
np.sqrt(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.exp(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.log(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.matmul

#
np.matmul(a, b) · np.dot(a, b)

Matrix product (@), with batched broadcasting over leading axes. dot follows NumPy's dot rules, including scalars and 1-D inputs. Backed by BLAS.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.matmul([[1, 2], [3, 4]], [[5], [6]]); // => [[17], [39]]
np.dot([1, 2, 3], [4, 5, 6]).item();      // => 32
TypeScript declaration
np.matmul(a: ArrayLike, b: ArrayLike): NDArray
np.dot(a: ArrayLike, b: ArrayLike): NDArray

np.outer

#
np.outer(a, b) · np.inner(a, b)

Outer product of two vectors (flattened), and the inner product over the last axes.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.outer([1, 2], [3, 4]);        // => [[3, 4], [6, 8]]
np.inner([1, 2], [3, 4]).item(); // => 11
TypeScript declaration
np.outer(a: ArrayLike, b: ArrayLike): NDArray
np.inner(a: ArrayLike, b: ArrayLike): NDArray

np.sin

#
np.sin(x, opts?) · np.cos · np.tan · np.arcsin · np.arccos · np.arctan (aliases np.asin · np.acos · np.atan)

Element-wise trigonometric functions and their inverses, in radians. Integer inputs give the smallest float that holds them (int8 → float16, int16 → float32, wider → float64). Complex inputs use complex loops.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.sin([0, Math.PI / 2]);  // => [0, 1]
np.cos([0]);               // => [1]
np.arctan([1]);            // => [0.7853981633974483]
np.asin === np.arcsin;     // => true
TypeScript declaration
np.sin(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.cos(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.tan(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.arcsin(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.arccos(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.arctan(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.asin(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.acos(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.atan(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.sinh

#
np.sinh(x, opts?) · np.cosh · np.tanh · np.arcsinh · np.arccosh · np.arctanh (aliases np.asinh · np.acosh · np.atanh)

Element-wise hyperbolic functions and their inverses, with complex loops.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.sinh([0]);         // => [0]
np.cosh([0]);         // => [1]
np.tanh([Infinity]);  // => [1]
np.arccosh([1]);      // => [0]
np.atanh === np.arctanh; // => true
TypeScript declaration
np.sinh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.cosh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.tanh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.arcsinh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.arccosh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.arctanh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.asinh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.acosh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.atanh(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.arctan2

#
np.arctan2(y, x, opts?) (alias np.atan2) · np.hypot(a, b, opts?)

arctan2 is the quadrant-aware angle of the point (x, y); hypot is sqrt(a² + b²) without intermediate overflow. Real (float) loops only.

Parameters

yArrayLike
An NDArray, nested JS array or scalar.
xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.arctan2([1, -1], [1, -1]); // => [0.7853981633974483, -2.356194490192345]
np.hypot([3, 5], [4, 12]);    // => [5, 13]
np.atan2 === np.arctan2;      // => true
TypeScript declaration
np.arctan2(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.atan2(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.hypot(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.deg2rad

#
np.deg2rad(x, opts?) · np.radians · np.rad2deg · np.degrees

Angle conversion. radians/degrees are the same operations as deg2rad/rad2deg.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.deg2rad([180]);       // => [3.141592653589793]
np.radians([90]);        // => [1.5707963267948966]
np.rad2deg([Math.PI]);   // => [180]
np.degrees([Math.PI / 2]); // => [90]
TypeScript declaration
np.deg2rad(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.radians(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.rad2deg(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.degrees(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.exp2

#
np.exp2(x, opts?) · np.expm1 · np.log2 · np.log10 · np.log1p

2**x, exp(x) - 1, base-2 / base-10 logarithms and log(1 + x). expm1/log1p stay accurate for tiny x. Complex loops are available.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.exp2([3, -1]);   // => [8, 0.5]
np.log2([8]);       // => [3]
np.log10([1000]);   // => [3]
np.expm1([0]);      // => [0]
np.log1p([0]);      // => [0]
TypeScript declaration
np.exp2(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.expm1(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.log2(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.log10(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.log1p(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.logaddexp

#
np.logaddexp(a, b, opts?) · np.logaddexp2(a, b, opts?)

log(exp(a) + exp(b)) and log2(2**a + 2**b) without overflow. Identity -Infinity, so .reduce works on empty input.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.logaddexp(0, 0).toArray();         // => 0.6931471805599453
np.logaddexp2(1, 1).toArray();        // => 2
np.logaddexp2.reduce([1, 1, 2]).toArray(); // => 3
TypeScript declaration
np.logaddexp(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.logaddexp2(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.cbrt

#
np.cbrt(x, opts?) · np.square(x, opts?) · np.reciprocal(x, opts?)

Cube root (real only); x*x and 1/x, which keep integer dtypes (integer reciprocal truncates, bool uses int8).

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.cbrt([-8, 27]);       // => [-2, 3]
np.square([2, -3]);      // => [4, 9]
np.reciprocal([4, 0.5]); // => [0.25, 2]
np.reciprocal([2, 1]);   // => [0, 1]
TypeScript declaration
np.cbrt(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.square(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.reciprocal(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.floor

#
np.floor(x, opts?) · np.ceil · np.trunc · np.fix · np.rint

Round down, up, toward zero (fix is the same as trunc) and to the nearest even integer. floor/ceil/trunc keep integer and bool dtypes; rint gives floats and also rounds complex parts.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.floor([-1.5, 1.5]);  // => [-2, 1]
np.ceil([-1.5, 1.5]);   // => [-1, 2]
np.trunc([-1.7, 1.7]);  // => [-1, 1]
np.fix([-1.7, 1.7]);    // => [-1, 1]
np.rint([0.5, 1.5]);    // => [0, 2]
TypeScript declaration
np.floor(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.ceil(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.trunc(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.fix(x: ArrayLike, opts?: RoundOptions | undefined): NDArray
np.rint(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.round

#
np.round(a, decimals = 0, { out? }) · np.around · a.round(decimals?)

Round half to even to decimals places; negative decimals round to tens, hundreds, …. Floats compute rint(a * 10**d) / 10**d like NumPy. Integer inputs keep their dtype.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
[decimals]number
Number of decimal places (integer, default 0).

Returns

NDArray

Example

TypeScript
np.round([0.5, 1.5, 2.5]);   // => [0, 2, 2]
np.round([1.25, 2.567], 2);  // => [1.25, 2.57]
np.around([15, 25], -1);     // => [20, 20]
np.array([3.14159]).round(3); // => [3.142]
TypeScript declaration
np.round(a: ArrayLike, decimals?: number | undefined, opts?: RoundOptions | undefined): NDArray
np.around(a: ArrayLike, decimals?: number | undefined, opts?: RoundOptions | undefined): NDArray
a.round(decimals?: number | undefined, opts?: RoundOptions | undefined): NDArray

np.positive

#
np.positive(x, opts?)

Element-wise +x (a copy). No bool loop, as in NumPy.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.positive([-3, 2]); // => [-3, 2]
TypeScript declaration
np.positive(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.fmod

#
np.fmod(a, b, opts?) · np.remainder (alias of np.mod) · np.trueDivide (alias of np.divide) · np.pow (alias of np.power) · np.absolute (alias of np.abs)

fmod is the C remainder: the result takes the sign of the dividend (unlike mod/remainder, which follow the divisor). Integer x % 0 is 0. The aliases are the same objects as the original ufuncs.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.fmod([-7, 7], 3);       // => [-1, 1]
np.remainder([-7, 7], 3);  // => [2, 1]
np.pow === np.power;       // => true
TypeScript declaration
np.fmod(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.remainder(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.mod(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.trueDivide(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.divide(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.pow(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.power(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.absolute(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.abs(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.floatPower

#
np.floatPower(a, b, opts?)

Element-wise a ** b computed in float64 (or complex128), so integer inputs can take negative exponents.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.floatPower([2, 3], 2);  // => [4, 9]
np.floatPower([2], -1);    // => [0.5]
TypeScript declaration
np.floatPower(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.sign

#
np.sign(x, opts?) · np.heaviside(x, h0, opts?) · np.fabs(x, opts?)

sign gives -1, 0 or 1 (NaN stays NaN; complex z/|z|). heaviside is 0 for x < 0, h0 at 0 and 1 for x > 0. fabs is the float-only absolute value.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.sign([-2, 0, 3]);            // => [-1, 0, 1]
np.heaviside([-1, 0, 2], 0.5);  // => [0, 0.5, 1]
np.fabs([-1.5]);                // => [1.5]
TypeScript declaration
np.sign(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.heaviside(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.fabs(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.maximum

#
np.maximum(a, b, opts?) · np.minimum · np.fmax · np.fmin

Element-wise maximum/minimum. maximum/minimum propagate NaN; fmax/fmin return the non-NaN operand. Use .reduce for an axis-wise max without an identity.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.maximum([1, 5], [3, 2]);      // => [3, 5]
np.minimum([NaN, 1], [0, 0]).toArray()[1]; // => 0
np.fmax([NaN, 1], [0, 0]);       // => [0, 1]
np.fmin([NaN, 1], [0, 0]);       // => [0, 0]
np.maximum.reduce([3, 9, 2]).toArray(); // => 9
TypeScript declaration
np.maximum(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.minimum(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.fmax(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.fmin(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.clip

#
np.clip(a, min?, max?, { out? }) · a.clip(min?, max?)

Limit values to [min, max]; null skips a side. Computed as minimum(maximum(a, min), max) like NumPy, so NaN propagates and min > max gives max. Also adds a.conjugate() (complex conjugate).

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
minArrayLike
An NDArray, nested JS array or scalar.
maxArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.clip([1, 5, 9], 2, 6);        // => [2, 5, 6]
np.clip([1, 5, 9], null, 4);     // => [1, 4, 4]
np.array([1, 5, 9]).clip(4);     // => [4, 5, 9]
np.array([1, 2]).conjugate();    // => [1, 2]
TypeScript declaration
np.clip(a: ArrayLike, min?: Bound, max?: Bound, opts?: ClipOptions | undefined): NDArray
a.clip(min?: Operand | null | undefined, max?: Operand | null | undefined, opts?: ClipOptions | undefined): NDArray

np.copysign

#
np.copysign(a, b, opts?) · np.nextafter(a, b, opts?) · np.spacing(x, opts?) · np.signbit(x, opts?)

Floating-point bit helpers: magnitude of a with the sign of b; the next representable value after a toward b; the gap to the next value away from zero; whether the sign bit is set (bool result, true for -0). Float loops only.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.copysign([3, 2], [-1, 1]);  // => [-3, 2]
np.nextafter([0], [-1]);       // => [-5e-324]
np.spacing([1]);               // => [2.220446049250313e-16]
np.signbit([-0.0, 1]);         // => [true, false]
TypeScript declaration
np.copysign(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.nextafter(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.spacing(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.signbit(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray

np.ldexp

#
np.ldexp(x, n, opts?)

x * 2**n for an integer exponent array n (non-integer or uint64 exponents raise DTypeError, as in NumPy).

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
nArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.ldexp([1.5, 1.5], [3, -1]); // => [12, 0.75]
TypeScript declaration
np.ldexp(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.gcd

#
np.gcd(a, b, opts?) · np.lcm(a, b, opts?)

Greatest common divisor and least common multiple of integers (results are non-negative). gcd has identity 0.

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.
[opts]UfuncOptions
out, where, dtype, casting, order (NumPy ufunc keywords).

Returns

NDArray

Example

TypeScript
np.gcd([12, -12, 7], [18, 18, 0]); // => [6, 6, 7]
np.lcm([4, -3], [6, 7]);           // => [12, 21]
np.gcd.reduce([12, 18, 27]).toArray(); // => 3
TypeScript declaration
np.gcd(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.lcm(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray

np.divmod

#
np.divmod(a, b, { out?, dtype?, casting? }) · np.modf(x, opts?) · np.frexp(x, opts?)

Two-output ufuncs returning [NDArray, NDArray]. divmod gives [floorDivide(a, b), mod(a, b)]; modf gives [fractional, integral] parts; frexp gives [mantissa, exponent] with x = m * 2**e and an int32 exponent. out is a pair (entries may be null).

Parameters

aArrayLike
An NDArray, nested JS array or scalar.
bArrayLike
An NDArray, nested JS array or scalar.
[opts]MultiUfuncOptions
out: [o1, o2], dtype, casting.

Returns

[NDArray, NDArray]

Example

TypeScript
np.divmod([7, -7], 2).map((x) => x.toArray()); // => [[3, -4], [1, 1]]
np.modf([-2.5]).map((x) => x.toArray());       // => [[-0.5], [-2]]
np.frexp([8]).map((x) => x.toArray());         // => [[0.5], [4]]
TypeScript declaration
np.divmod(a: Operand, b: Operand, opts?: MultiUfuncOptions | undefined): [NDArray, NDArray]
np.modf(x: ArrayLike, opts?: MultiUfuncOptions | undefined): [NDArray, NDArray]
np.frexp(x: ArrayLike, opts?: MultiUfuncOptions | undefined): [NDArray, NDArray]

np.i0

#
np.i0(x) · np.sinc(x)

i0 is the modified Bessel function of the first kind, order 0 (real input; float16/float32 kept, otherwise float64). sinc is the normalized sin(pi x) / (pi x), 1 at 0, with complex support. Not ufunc objects (as in NumPy).

Parameters

xArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.i0([0]);         // => [1]
np.sinc([0, 0.5]);  // => [1, 0.6366197723675814]
TypeScript declaration
np.i0(x: ArrayLike): NDArray
np.sinc(x: ArrayLike): NDArray

np.nanToNum

#
np.nanToNum(x, { copy?, nan?, posinf?, neginf? })

Replace NaN with nan (default 0) and ±Infinity with posinf/neginf (default: the dtype's largest finite values). Complex values are fixed part by part; non-float input is returned unchanged.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[opts]NanToNumOptions
copy (default true), scalar nan, posinf, neginf.

Returns

NDArray

Example

TypeScript
np.nanToNum([NaN, 1]);                     // => [0, 1]
np.nanToNum([NaN, Infinity], { posinf: 9 }); // => [0, 9]
TypeScript declaration
np.nanToNum(x: ArrayLike, opts?: NanToNumOptions | undefined): NDArray

np.realIfClose

#
np.realIfClose(x, tol = 100)

Return the real part when every imaginary part is below tol (counted in machine epsilons when tol > 1); otherwise return x unchanged.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.
[tol]number
Tolerance (default 100 epsilons).

Returns

NDArray

Example

TypeScript
np.realIfClose([{ re: 2, im: 1e-15 }]); // => [2]
np.realIfClose([{ re: 2, im: 0.5 }]).dtype.name; // => "complex128"
TypeScript declaration
np.realIfClose(x: ArrayLike, tol?: number | undefined): NDArray

np.unwrap

#
np.unwrap(p, { discont?, axis? = -1, period? = 2π })

Remove jumps between neighbours larger than discont (default period / 2) by adding multiples of period. Integer input with an integer period keeps its dtype.

Parameters

pArrayLike
An NDArray, nested JS array or scalar.
[opts]UnwrapOptions
discont, axis, period.

Returns

NDArray

Example

TypeScript
np.unwrap([0, 7, 14], { period: 10 }); // => [0, -3, -6]
np.unwrap([0, 1, 2]);                  // => [0, 1, 2]
TypeScript declaration
np.unwrap(p: ArrayLike, opts?: UnwrapOptions | undefined): NDArray