Mathematical functions

Note

Currently, most of the math functions only support inputs and outputs of the same dtype. This limitation usually results in imprecise outputs for ndarrays with integral dtype while floating-point values are expected in the output. Appropriate handling of ndarrays integral dtypes is in active development.

Trigonometric functions

sin(x[, out])

Trigonometric sine, element-wise.

cos(x[, out])

Cosine, element-wise.

tan(x[, out])

Compute tangent element-wise.

arcsin(x[, out])

Inverse sine, element-wise.

arccos(x[, out])

Trigonometric inverse cosine, element-wise.

arctan(x[, out])

Trigonometric inverse tangent, element-wise.

degrees(x[, out])

Convert angles from radians to degrees.

radians(x[, out])

Convert angles from degrees to radians.

hypot(x1, x2[, out])

Given the “legs” of a right triangle, return its hypotenuse.

arctan2(x1, x2[, out])

Element-wise arc tangent of x1/x2 choosing the quadrant correctly.

deg2rad(x[, out])

Convert angles from degrees to radians.

rad2deg(x[, out])

Convert angles from radians to degrees.

unwrap(p[, discont, axis])

Unwrap by changing deltas between values to 2*pi complement.

Hyperbolic functions

sinh(x[, out])

Hyperbolic sine, element-wise.

cosh(x[, out])

Hyperbolic cosine, element-wise.

tanh(x[, out])

Compute hyperbolic tangent element-wise.

arcsinh(x[, out])

Inverse hyperbolic cosine, element-wise.

arccosh(x[, out])

Inverse hyperbolic cosine, element-wise.

arctanh(x[, out])

Inverse hyperbolic tangent, element-wise.

Rounding

rint(x[, out])

Round elements of the array to the nearest integer.

fix(x[, out])

Round an array of floats element-wise to nearest integer towards zero.

floor(x[, out])

Return the floor of the input, element-wise.

ceil(x[, out])

Return the ceiling of the input, element-wise.

trunc(x[, out])

Return the truncated value of the input, element-wise.

around(x[, decimals, out])

Evenly round to the given number of decimals.

round_(a[, decimals, out])

Round an array to the given number of decimals.

Sums, products, differences

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

Sum of array elements over a given axis.

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

Return the product of array elements over a given axis.

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

Return the cumulative sum of the elements along a given axis.

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

Return the product of array elements over a given axis treating Not a Numbers (NaNs) as ones.

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

Return the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.

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

Return the cumulative product of elements along a given axis.

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

Return the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one.

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

Return the cumulative sum of array elements over 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.

ediff1d(ary[, to_end, to_begin])

The differences between consecutive elements of an array.

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

Return the cross product of two (arrays of) vectors.

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

Integrate along the given axis using the composite trapezoidal rule.

Exponents and logarithms

exp(x[, out])

Calculate the exponential of all elements in the input array.

expm1(x[, out])

Calculate exp(x) - 1 for all elements in the array.

log(x[, out])

Natural logarithm, element-wise.

log10(x[, out])

Return the base 10 logarithm of the input array, element-wise.

log2(x[, out])

Base-2 logarithm of x.

log1p(x[, out])

Return the natural logarithm of one plus the input array, element-wise.

logaddexp(x1, x2[, out])

Logarithm of the sum of exponentiations of the inputs.

Other special functions

i0(x)

Modified Bessel function of the first kind, order 0.

Floating point routines

ldexp(x1, x2[, out])

Returns x1 * 2**x2, element-wise.

signbit(x, /[, out, where, casting, order, …])

Returns element-wise True where signbit is set (less than zero).

copysign(x1, x2[, out])

Change the sign of x1 to that of x2, element-wise.

frexp(x[, out1, out2], / [[, out, where, …])

Decompose the elements of x into mantissa and twos exponent.

spacing(x, /[, out, where, casting, order, …])

Return the distance between x and the nearest adjacent number.

Rational routines

lcm(x1, x2[, out])

Returns the lowest common multiple of |x1| and |x2|

gcd(x1, x2[, out])

Returns the greatest common divisor of |x1| and |x2|

Arithmetic operations

add(x1, x2[, out])

Add arguments element-wise.

reciprocal(x[, out])

Return the reciprocal of the argument, element-wise.

negative(x[, out])

Numerical negative, element-wise.

divide(x1, x2[, out])

Returns a true division of the inputs, element-wise.

power(x1, x2[, out])

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

subtract(x1, x2[, out])

Subtract arguments element-wise.

mod(x1, x2[, out])

Return element-wise remainder of division.

multiply(x1, x2[, out])

Multiply arguments element-wise.

true_divide(x1, x2[, out])

Returns a true division of the inputs, element-wise.

remainder(x1, x2[, out])

Return element-wise remainder of division.

positive(x[, out])

Computes the numerical positive of each element x_i (i.e.,`y_i = +x_i`) of the input array x .

float_power(x1, x2, /[, out, where, …])

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

fmod(x1, x2[, out])

Return element-wise remainder of division.

modf(x[, out1, out2], / [[, out, where, …])

Return the fractional and integral parts of an array, element-wise.

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

Return element-wise quotient and remainder simultaneously.

floor_divide(x1, x2[, out])

Return the largest integer smaller or equal to the division of the inputs.

Miscellaneous

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

Clip (limit) the values in an array.

sqrt(x[, out])

Return the non-negative square-root of an array, element-wise.

cbrt(x[, out])

Return the cube-root of an array, element-wise.

square(x[, out])

Return the element-wise square of the input.

absolute(x[, out])

Calculate the absolute value element-wise.

sign(x[, out])

Returns an element-wise indication of the sign of a number.

maximum(x1, x2[, out])

Returns element-wise maximum of the input arrays with broadcasting.

minimum(x1, x2[, out])

Returns element-wise minimum of the input arrays with broadcasting.

fabs(x[, out])

Calculate the absolute value element-wise.

heaviside(x1, x2, /[, out, where, casting, …])

Compute the Heaviside step function.

fmax(x1, x2[, out])

Returns element-wise maximum of the input arrays with broadcasting.

fmin(x1, x2[, out])

Returns element-wise minimum of the input arrays with broadcasting.

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.

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

One-dimensional linear interpolation.