Hyperbolic Functions with NumPy
NumPy provides built-in universal functions (ufuncs) to work with hyperbolic functions such as sinh(), cosh(), and tanh(). These functions take values in radians and return the corresponding hyperbolic sine, cosine, and tangent values.Program:
Calculate Hyperbolic Sine of π/2
import numpy as np
x = np.sinh(np.pi / 2)
print(x)
Output:
2.3012989023072947
Program:
Calculate Hyperbolic Cosine for Multiple Values
You can also calculate hyperbolic cosine for an entire array of values:
You can also calculate hyperbolic cosine for an entire array of values:
import numpy as np
arr = np.array([np.pi/2, np.pi/3, np.pi/4, np.pi/5])
x = np.cosh(arr)
print(x)
Output:
[2.50917848 1.60028686 1.32460909 1.20126043]
This array contains the hyperbolic cosine values of each angle in arr.
Inverse Hyperbolic Functions (Finding Angles)
NumPy also provides inverse hyperbolic functions to compute angles from given hyperbolic sine, cosine, or tangent values:arcsinh() – Inverse of sinh
arccosh() – Inverse of cosh
arctanh() – Inverse of tanh
These functions return the angle in radians.
Program:
Find the Inverse Hyperbolic Sine of 1.0
import numpy as np
x = np.arcsinh(1.0)
print(x)
Output:
0.881373587019543
Program:
Find Inverse Hyperbolic Tangent for Array of Values
import numpy as np
arr = np.array([0.1, 0.2, 0.5])
x = np.arctanh(arr)
print(x)
Output:
[0.10033535 0.20273255 0.54930614]