Mathematical functions#

Trigonometric functions#

sin(x, /[, out, casting, dtype])

Elementwise sine function.

cos(x, /[, out, casting, dtype])

Elementwise cosine function.

tan(x, /[, out, casting, dtype])

Elementwise tangent function.

arcsin(x, /[, out, casting, dtype])

Elementwise inverse-sine function (a.k.a.

arccos(x, /[, out, casting, dtype])

Elementwise inverse-cosine function (a.k.a.

arctan(x, /[, out, casting, dtype])

Elementwise inverse-tangent function (a.k.a.

hypot(x1, x2, /[, out, casting, dtype])

Computes the hypoteneous of orthogonal vectors of given length.

arctan2(x1, x2, /[, out, casting, dtype])

Elementwise inverse-tangent of the ratio of two arrays.


rad2deg(x, /, out=None, *, casting='same_kind', dtype=None)

radians(x, /[, out, casting, dtype])

Converts angles from degrees to radians elementwise.

unwrap(p[, discont, axis, period])

Unwrap by taking the complement of large deltas w.r.t.


radians(x, /, out=None, *, casting='same_kind', dtype=None)

rad2deg(x, /[, out, casting, dtype])

Converts angles from radians to degrees elementwise.

Hyperbolic functions#

sinh(x, /[, out, casting, dtype])

Elementwise hyperbolic sine function.

cosh(x, /[, out, casting, dtype])

Elementwise hyperbolic cosine function.

tanh(x, /[, out, casting, dtype])

Elementwise hyperbolic tangent function.

arcsinh(x, /[, out, casting, dtype])

Elementwise inverse of hyperbolic sine function.

arccosh(x, /[, out, casting, dtype])

Elementwise inverse of hyperbolic cosine function.

arctanh(x, /[, out, casting, dtype])

Elementwise inverse of hyperbolic tangent function.


around(a[, decimals, out])

Rounds to the given number of decimals.

round_(a[, decimals, out])

rint(x, /[, out, casting, dtype])

Rounds each element of an array to the nearest integer.

fix(x, /[, out, casting, dtype])

If given value x is positive, it return floor(x).

floor(x, /[, out, casting, dtype])

Rounds each element of an array to its floor integer.

ceil(x, /[, out, casting, dtype])

Rounds each element of an array to its ceiling integer.

trunc(x, /[, out, casting, dtype])

Rounds each element of an array towards zero.

Sums, products, differences#

prod(a[, axis, dtype, out, keepdims])

Returns the product of an array along given axes.

sum(a[, axis, dtype, out, keepdims])

Returns the sum of an array along given axes.

nanprod(a[, axis, dtype, out, keepdims])

Returns the product of an array along given axes treating Not a Numbers (NaNs) as zero.

nansum(a[, axis, dtype, out, keepdims])

Returns the sum of an array along given axes treating Not a Numbers (NaNs) as zero.

cumprod(a[, axis, dtype, out])

Returns the cumulative product of an array along a given axis.

cumsum(a[, axis, dtype, out])

Returns the cumulative sum of an array along a given axis.

nancumprod(a[, axis, dtype, out])

Returns the cumulative product of an array along a given axis treating Not a Numbers (NaNs) as one.

nancumsum(a[, axis, dtype, out])

Returns the cumulative sum of an array along a given axis treating Not a Numbers (NaNs) as zero.

diff(a[, n, axis, prepend, append])

Calculate the n-th discrete difference along the given axis.

gradient(f, *varargs[, axis, edge_order])

Return the gradient of an N-dimensional array.

ediff1d(arr[, to_end, to_begin])

Calculates the difference between consecutive elements of an array.

cross(a, b[, axisa, axisb, axisc, axis])

Returns the cross product of two vectors.

trapz(y[, x, dx, axis])

Integrate along the given axis using the composite trapezoidal rule.

Exponents and logarithms#

exp(x, /[, out, casting, dtype])

Elementwise exponential function.

expm1(x, /[, out, casting, dtype])

Computes exp(x) - 1 elementwise.

exp2(x, /[, out, casting, dtype])

Elementwise exponentiation with base 2.

log(x, /[, out, casting, dtype])

Elementwise natural logarithm function.

log10(x, /[, out, casting, dtype])

Elementwise common logarithm function.

log2(x, /[, out, casting, dtype])

Elementwise binary logarithm function.

log1p(x, /[, out, casting, dtype])

Computes log(1 + x) elementwise.

logaddexp(x1, x2, /[, out, casting, dtype])

Computes log(exp(x1) + exp(x2)) elementwise.

logaddexp2(x1, x2, /[, out, casting, dtype])

Computes log2(exp2(x1) + exp2(x2)) elementwise.

Other special functions#

i0(x, /[, out, casting, dtype])

Modified Bessel function of the first kind, order 0.

sinc(x, /[, out, casting, dtype])

Elementwise sinc function.

Floating point routines#

signbit(x, /[, out, casting, dtype])

Tests elementwise if the sign bit is set (i.e.

copysign(x1, x2, /[, out, casting, dtype])

Returns the first argument with the sign bit of the second elementwise.

frexp(x[, out1, out2], / [[, out, casting, ...])

Decomposes each element to mantissa and two's exponent.

ldexp(x1, x2, /[, out, casting, dtype])

Computes x1 * 2 ** x2 elementwise.

nextafter(x1, x2, /[, out, casting, dtype])

Computes the nearest neighbor float values towards the second argument.

Rational routines#

lcm(x1, x2, /[, out, casting, dtype])

Computes lcm of x1 and x2 elementwise.

gcd(x1, x2, /[, out, casting, dtype])

Computes gcd of x1 and x2 elementwise.

Arithmetic operations#

add(x1, x2, /[, out, casting, dtype])

Adds two arrays elementwise.

reciprocal(x, /[, out, casting, dtype])

Computes 1 / x elementwise.

positive(x, /[, out, casting, dtype])

Takes numerical positive elementwise.

negative(x, /[, out, casting, dtype])

Takes numerical negative elementwise.

multiply(x1, x2, /[, out, casting, dtype])

Multiplies two arrays elementwise.


true_divide(x1, x2, /, out=None, *, casting='same_kind', dtype=None)

power(x1, x2, /[, out, casting, dtype])

Computes x1 ** x2 elementwise.

subtract(x1, x2, /[, out, casting, dtype])

Subtracts arguments elementwise.

true_divide(x1, x2, /[, out, casting, dtype])

Elementwise true division (i.e.

floor_divide(x1, x2, /[, out, casting, dtype])

Elementwise floor division (i.e.

float_power(x1, x2, /[, out, casting, dtype])

First array elements raised to powers from second array, element-wise.

fmod(x1, x2, /[, out, casting, dtype])

Computes the remainder of C division elementwise.

mod(x1, x2, /[, out, casting, dtype])

Computes the remainder of Python division elementwise.

modf(x[, out1, out2], / [[, out, casting, dtype])

Extracts the fractional and integral parts of an array elementwise.


mod(x1, x2, /, out=None, *, casting='same_kind', dtype=None)

divmod(x1, x2[, out1, out2], / [[, out, ...])

Handling complex numbers#

angle(z[, deg])

Returns the angle of the complex argument.


Returns the real part of the elements of the array.


Returns the imaginary part of the elements of the array.


conjugate(x, /, out=None, *, casting='same_kind', dtype=None)

conjugate(x, /[, out, casting, dtype])

Returns the complex conjugate, element-wise.


convolve(a, v[, mode])

Returns the discrete, linear convolution of two one-dimensional sequences.

clip(a, a_min, a_max[, out])

Clips the values of an array to a given interval.

sqrt(x, /[, out, casting, dtype])

Elementwise square root function.

cbrt(x, /[, out, casting, dtype])

Elementwise cube root function.

square(x, /[, out, casting, dtype])

Elementwise square function.

absolute(x, /[, out, casting, dtype])

Elementwise absolute value function.

fabs(x, /[, out, casting, dtype])

Calculates absolute values element-wise.

sign(x, /[, out, casting, dtype])

Elementwise sign function.

maximum(x1, x2, /[, out, casting, dtype])

Takes the maximum of two arrays elementwise.

minimum(x1, x2, /[, out, casting, dtype])

Takes the minimum of two arrays elementwise.

fmax(x1, x2, /[, out, casting, dtype])

Takes the maximum of two arrays elementwise.

fmin(x1, x2, /[, out, casting, dtype])

Takes the minimum of two arrays elementwise.

nan_to_num(x[, copy, nan, posinf, neginf])

Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.

heaviside(x1, x2, /[, out, casting, dtype])

Compute the Heaviside step function.

real_if_close(a[, tol])

If input is complex with all imaginary parts close to zero, return real parts.

interp(x, xp, fp[, left, right, period])

One-dimensional linear interpolation.