Skip to main content
NumPy provides a complete set of trigonometric and hyperbolic functions that operate element-wise on arrays.

Trigonometric Functions

numpy.sin

numpy.sin(x, /, out=None, *, where=True, **kwargs)
Trigonometric sine, element-wise. Parameters:
  • x : array_like - Angle, in radians (2π2\pi rad equals 360 degrees).
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • y : array_like - The sine of each element of x.
Mathematical Formula: y=sin(x)y = \sin(x) Notes: The sine is one of the fundamental functions of trigonometry. Consider a circle of radius 1 centered on the origin. A ray from the origin makes an angle xx (measured counter-clockwise from the +x+x axis). The yy coordinate of the ray’s intersection with the unit circle is sin(x)\sin(x). It ranges from -1 to +1, with zeroes at multiples of π\pi. Examples:
import numpy as np

# Sine of π/2
np.sin(np.pi/2.)
# 1.0

# Sines of angles in degrees
np.sin(np.array((0., 30., 45., 60., 90.)) * np.pi / 180.)
# array([ 0.        ,  0.5       ,  0.70710678,  0.8660254 ,  1.        ])

# Plot the sine function
import matplotlib.pyplot as plt
x = np.linspace(-np.pi, np.pi, 201)
plt.plot(x, np.sin(x))
plt.xlabel('Angle [rad]')
plt.ylabel('sin(x)')
plt.show()

numpy.cos

numpy.cos(x, /, out=None, *, where=True, **kwargs)
Cosine element-wise. Parameters:
  • x : array_like - Input array in radians.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • y : ndarray - The corresponding cosine values.
Mathematical Formula: y=cos(x)y = \cos(x) Examples:
import numpy as np

np.cos(np.array([0, np.pi/2, np.pi]))
# array([  1.00000000e+00,   6.12303177e-17,  -1.00000000e+00])

numpy.tan

numpy.tan(x, /, out=None, *, where=True, **kwargs)
Compute tangent element-wise. Parameters:
  • x : array_like - Input array in radians.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • y : ndarray - The tangent of each element of x.
Mathematical Formula: y=tan(x)=sin(x)cos(x)y = \tan(x) = \frac{\sin(x)}{\cos(x)} Notes: Equivalent to np.sin(x)/np.cos(x) element-wise.

Inverse Trigonometric Functions

numpy.arcsin

numpy.arcsin(x, /, out=None, *, where=True, **kwargs)
Inverse sine, element-wise. Parameters:
  • x : array_like - y-coordinate on the unit circle.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • angle : ndarray - The inverse sine of each element in x, in radians and in the closed interval [π/2,π/2][-\pi/2, \pi/2].
Mathematical Formula: y=arcsin(x)=sin1(x)y = \arcsin(x) = \sin^{-1}(x) Notes:
  • For real-valued input, domain is [1,1][-1, 1].
  • arcsin is a multivalued function. The convention is to return the angle whose real part lies in [π/2,π/2][-\pi/2, \pi/2].
  • For complex-valued input, has branch cuts [,1][-\infty, -1] and [1,][1, \infty].

numpy.arccos

numpy.arccos(x, /, out=None, *, where=True, **kwargs)
Trigonometric inverse cosine, element-wise. Parameters:
  • x : array_like - x-coordinate on the unit circle. For real arguments, domain is [1,1][-1, 1].
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • angle : ndarray - The angle of the ray intersecting the unit circle at the given x-coordinate in radians [0,π][0, \pi].
Mathematical Formula: y=arccos(x)=cos1(x)y = \arccos(x) = \cos^{-1}(x) The inverse of cos so that if y = cos(x), then x = arccos(y). Examples:
import numpy as np

np.arccos([1, -1])
# array([ 0.        ,  3.14159265])

numpy.arctan

numpy.arctan(x, /, out=None, *, where=True, **kwargs)
Trigonometric inverse tangent, element-wise. Parameters:
  • x : array_like - Input values.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • out : ndarray - The inverse tangent of each element in x, in radians and in the closed interval [π/2,π/2][-\pi/2, \pi/2].
Mathematical Formula: y=arctan(x)=tan1(x)y = \arctan(x) = \tan^{-1}(x)

numpy.arctan2

numpy.arctan2(x1, x2, /, out=None, *, where=True, **kwargs)
Element-wise arc tangent of x1/x2 choosing the quadrant correctly. Parameters:
  • x1 : array_like - y-coordinates.
  • x2 : array_like - x-coordinates.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • angle : ndarray - Angle in radians, in the range [π,π][-\pi, \pi].
Mathematical Formula: θ=arctan2(y,x)\theta = \arctan2(y, x) where the quadrant is determined by the signs of both x1 and x2. Notes: arctan2 is useful for converting Cartesian coordinates (x,y)(x, y) to polar coordinates (r,θ)(r, \theta). The result respects the signs of both inputs to determine the correct quadrant.

numpy.hypot

numpy.hypot(x1, x2, /, out=None, *, where=True, **kwargs)
Given the “legs” of a right triangle, return its hypotenuse. Parameters:
  • x1, x2 : array_like - Leg of the triangle(s).
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • z : ndarray - The hypotenuse of the triangle(s).
Mathematical Formula: z=x12+x22z = \sqrt{x_1^2 + x_2^2} Equivalent to sqrt(x1**2 + x2**2), but avoids overflow for large values. Examples:
import numpy as np

np.hypot(3, 4)
# 5.0

np.hypot([3, 4], [4, 3])
# array([5., 5.])

Hyperbolic Functions

numpy.sinh

numpy.sinh(x, /, out=None, *, where=True, **kwargs)
Hyperbolic sine, element-wise. Parameters:
  • x : array_like - Input array.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • y : ndarray - The corresponding hyperbolic sine values.
Mathematical Formula: sinh(x)=exex2\sinh(x) = \frac{e^x - e^{-x}}{2} Equivalent to 1/2 * (np.exp(x) - np.exp(-x)) or -1j * np.sin(1j*x). Examples:
import numpy as np

np.sinh(0)
# 0.0

np.sinh(np.pi*1j/2)
# 1j

numpy.cosh

numpy.cosh(x, /, out=None, *, where=True, **kwargs)
Hyperbolic cosine, element-wise. Parameters:
  • x : array_like - Input array.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • out : ndarray or scalar - Output array of same shape as x.
Mathematical Formula: cosh(x)=ex+ex2\cosh(x) = \frac{e^x + e^{-x}}{2} Equivalent to 1/2 * (np.exp(x) + np.exp(-x)) and np.cos(1j*x). Examples:
import numpy as np

np.cosh(0)
# 1.0

# The hyperbolic cosine describes the shape of a hanging cable
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 1000)
plt.plot(x, np.cosh(x))
plt.show()

numpy.tanh

numpy.tanh(x, /, out=None, *, where=True, **kwargs)
Compute hyperbolic tangent element-wise. Parameters:
  • x : array_like - Input array.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • y : ndarray - The corresponding hyperbolic tangent values.
Mathematical Formula: tanh(x)=sinh(x)cosh(x)=exexex+ex\tanh(x) = \frac{\sinh(x)}{\cosh(x)} = \frac{e^x - e^{-x}}{e^x + e^{-x}}

Inverse Hyperbolic Functions

numpy.arcsinh

numpy.arcsinh(x, /, out=None, *, where=True, **kwargs)
Inverse hyperbolic sine element-wise. Mathematical Formula: y=sinh1(x)y = \sinh^{-1}(x)

numpy.arccosh

numpy.arccosh(x, /, out=None, *, where=True, **kwargs)
Inverse hyperbolic cosine, element-wise. Parameters:
  • x : array_like - Input array.
  • out : ndarray, optional - A location into which the result is stored.
  • where : array_like, optional - Condition to broadcast over the input.
Returns:
  • arccosh : ndarray - Array of the same shape as x.
Mathematical Formula: y=cosh1(x)y = \cosh^{-1}(x) Notes: arccosh is a multivalued function. The convention is to return the z whose imaginary part lies in [π,π][-\pi, \pi] and the real part in [0,][0, \infty]. Examples:
import numpy as np

np.arccosh([np.e, 10.0])
# array([ 1.65745445,  2.99322285])

np.arccosh(1)
# 0.0

numpy.arctanh

numpy.arctanh(x, /, out=None, *, where=True, **kwargs)
Inverse hyperbolic tangent element-wise. Mathematical Formula: y=tanh1(x)y = \tanh^{-1}(x)

See Also

Arithmetic Functions

Basic arithmetic operations

Exponential Functions

exp, log, and power functions

Rounding Functions

floor, ceil, round, and truncation

Special Functions

sqrt, square, gcd, and lcm

Build docs developers (and LLMs) love