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.
| Name | Summary |
|---|---|
np.add | Element-wise +, -, *, /. |
np.floorDivide | Python-style floor division and modulo: the result of mod takes the sign of the divisor. |
np.power | Element-wise a ** b. |
np.abs | Absolute value and negation. |
np.real | Complex helpers. |
np.sqrt | Square root, e^x and the natural log. |
np.matmul | Matrix product (@), with batched broadcasting over leading axes. |
np.outer | Outer product of two vectors (flattened), and the inner product over the last axes. |
np.sin | Element-wise trigonometric functions and their inverses, in radians. |
np.sinh | Element-wise hyperbolic functions and their inverses, with complex loops. |
np.arctan2 | arctan2 is the quadrant-aware angle of the point (x, y); hypot is sqrt(a² + b²) without intermediate overflow. |
np.deg2rad | Angle conversion. |
np.exp2 | 2**x, exp(x) - 1, base-2 / base-10 logarithms and log(1 + x). |
np.logaddexp | log(exp(a) + exp(b)) and log2(2**a + 2**b) without overflow. |
np.cbrt | Cube root (real only); x*x and 1/x, which keep integer dtypes (integer reciprocal truncates, bool uses int8). |
np.floor | Round down, up, toward zero (fix is the same as trunc) and to the nearest even integer. |
np.round | Round half to even to decimals places; negative decimals round to tens, hundreds, …. |
np.positive | Element-wise +x (a copy). |
np.fmod | fmod is the C remainder: the result takes the sign of the dividend (unlike mod/remainder, which follow the divisor). |
np.floatPower | Element-wise a ** b computed in float64 (or complex128), so integer inputs can take negative exponents. |
np.sign | sign gives -1, 0 or 1 (NaN stays NaN; complex z/|z|). |
np.maximum | Element-wise maximum/minimum. |
np.clip | Limit values to [min, max]; null skips a side. |
np.copysign | 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). |
np.ldexp | x * 2**n for an integer exponent array n (non-integer or uint64 exponents raise DTypeError, as in NumPy). |
np.gcd | Greatest common divisor and least common multiple of integers (results are non-negative). |
np.divmod | Two-output ufuncs returning [NDArray, NDArray]. |
np.i0 | i0 is the modified Bessel function of the first kind, order 0 (real input; float16/float32 kept, otherwise float64). |
np.nanToNum | Replace NaN with nan (default 0) and ±Infinity with posinf/neginf (default: the dtype's largest finite values). |
np.realIfClose | Return the real part when every imaginary part is below tol (counted in machine epsilons when tol > 1); otherwise return x unchanged. |
np.unwrap | Remove 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
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): NDArraynp.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
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): NDArraynp.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
np.power([1, 2, 3], 2); // => [1, 4, 9]
np.power(2, [0.5, -1]).toArray()[1]; // => 0.5TypeScript declaration
np.power(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArraynp.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
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): NDArraynp.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]booleanangleonly: return degrees. Defaultfalse.
Returns
NDArray (boolean for iscomplexobj / isrealobj)
Example
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]); // => trueTypeScript 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): booleannp.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
np.sqrt([4, 9]); // => [2, 3]
np.exp([0]); // => [1]
np.log([1]); // => [0]
Number.isNaN(np.sqrt(-1).item()); // => trueTypeScript declaration
np.sqrt(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.exp(a: ArrayLike, opts?: UfuncOptions | undefined): NDArray
np.log(a: ArrayLike, opts?: UfuncOptions | undefined): NDArraynp.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
np.matmul([[1, 2], [3, 4]], [[5], [6]]); // => [[17], [39]]
np.dot([1, 2, 3], [4, 5, 6]).item(); // => 32TypeScript declaration
np.matmul(a: ArrayLike, b: ArrayLike): NDArray
np.dot(a: ArrayLike, b: ArrayLike): NDArraynp.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
np.outer([1, 2], [3, 4]); // => [[3, 4], [6, 8]]
np.inner([1, 2], [3, 4]).item(); // => 11TypeScript declaration
np.outer(a: ArrayLike, b: ArrayLike): NDArray
np.inner(a: ArrayLike, b: ArrayLike): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.sin([0, Math.PI / 2]); // => [0, 1]
np.cos([0]); // => [1]
np.arctan([1]); // => [0.7853981633974483]
np.asin === np.arcsin; // => trueTypeScript 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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.sinh([0]); // => [0]
np.cosh([0]); // => [1]
np.tanh([Infinity]); // => [1]
np.arccosh([1]); // => [0]
np.atanh === np.arctanh; // => trueTypeScript 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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.arctan2([1, -1], [1, -1]); // => [0.7853981633974483, -2.356194490192345]
np.hypot([3, 5], [4, 12]); // => [5, 13]
np.atan2 === np.arctan2; // => trueTypeScript 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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.logaddexp(0, 0).toArray(); // => 0.6931471805599453
np.logaddexp2(1, 1).toArray(); // => 2
np.logaddexp2.reduce([1, 1, 2]).toArray(); // => 3TypeScript declaration
np.logaddexp(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.logaddexp2(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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): NDArraynp.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
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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.positive([-3, 2]); // => [-3, 2]TypeScript declaration
np.positive(a: ArrayLike, opts?: UfuncOptions | undefined): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.fmod([-7, 7], 3); // => [-1, 1]
np.remainder([-7, 7], 3); // => [2, 1]
np.pow === np.power; // => trueTypeScript 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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.floatPower([2, 3], 2); // => [4, 9]
np.floatPower([2], -1); // => [0.5]TypeScript declaration
np.floatPower(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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(); // => 9TypeScript 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): NDArraynp.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
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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
np.ldexp([1.5, 1.5], [3, -1]); // => [12, 0.75]TypeScript declaration
np.ldexp(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArraynp.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]UfuncOptionsout,where,dtype,casting,order(NumPy ufunc keywords).
Returns
NDArray
Example
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(); // => 3TypeScript declaration
np.gcd(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArray
np.lcm(a: Operand, b: Operand, opts?: UfuncOptions | undefined): NDArraynp.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]MultiUfuncOptionsout: [o1, o2],dtype,casting.
Returns
[NDArray, NDArray]
Example
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
np.i0([0]); // => [1]
np.sinc([0, 0.5]); // => [1, 0.6366197723675814]TypeScript declaration
np.i0(x: ArrayLike): NDArray
np.sinc(x: ArrayLike): NDArraynp.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]NanToNumOptionscopy(default true), scalarnan,posinf,neginf.
Returns
NDArray
Example
np.nanToNum([NaN, 1]); // => [0, 1]
np.nanToNum([NaN, Infinity], { posinf: 9 }); // => [0, 9]TypeScript declaration
np.nanToNum(x: ArrayLike, opts?: NanToNumOptions | undefined): NDArraynp.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
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): NDArraynp.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]UnwrapOptionsdiscont,axis,period.
Returns
NDArray
Example
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