NumPy UFunctions Hyperbolic
The purpose of this article is to provide a detailed explanation of Numpy Ufunc Hyperbolic with effective examples.
NumPy Universal functions, commonly known as ufuncs, are the core of NumPy’s functionality.
They are versatile and efficient functions that operate on ndarrays, and are implemented in C for faster performance.
Numpy Ufunc Hyperbolic
Hyperbolic functions are mathematical functions that are related to the hyperbola. These functions are defined in terms of the exponential function and its inverse.
According to Numpy Ufunc hyperbolic, NumPy offers the functions sinh(), cosh(), and tanh(), which accept radian values and generate the respective sinh, cosh, and tanh values.
Let’s start by discussing the basic Numpy Ufunc Hyperbolic:
sinh(x)
The sinh function returns the hyperbolic sine of the input array element-wise. The formula for calculating the sinh function is given by:
sinh(x) = (e^x - e^(-x))/2
Syntax
numpy.sinh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
cosh(x)
The cosh function returns the hyperbolic cosine of the input array element-wise. The formula for calculating the cosh function is given by:
cosh(x) = (e^x + e^(-x))/2
Syntax
numpy.cosh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
tanh(x)
The tanh function returns the hyperbolic tangent of the input array element-wise. The formula for calculating the tanh function is given by:
tanh(x) = (e^x - e^(-x))/(e^x + e^(-x))
Syntax
numpy.tanh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
asinh(x)
The asinh function returns the inverse hyperbolic sine of the input array element-wise. The formula for calculating the asinh function is given by:
asinh(x) = ln(x + sqrt(x^2 + 1))
Syntax
numpy.arcsinh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
acosh(x)
The acosh function returns the inverse hyperbolic cosine of the input array element-wise. The formula for calculating the acosh function is given by:
acosh(x) = ln(x + sqrt(x^2 - 1))
Syntax
numpy.arccosh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
atanh(x)
The atanh function returns the inverse hyperbolic tangent of the input array element-wise. The formula for calculating the atanh function is given by:
atanh(x) = (ln((1+x)/(1-x)))/2
Syntax
numpy.arctanh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
- Here, x represents the input array on which the hyperbolic function is to be performed.
- The out parameter is an optional output array in which the result is stored.
- The where parameter is a boolean array that acts as a mask for the input array.
- The casting parameter determines how the input is cast for the calculation.
- The order parameter determines the memory layout of the output array.
- The dtype parameter is the data type of the output array.
- The subok parameter specifies whether to allow subclass instances of the input array.
- The signature parameter is used to specify the signature of the ufunc.
- The extobj parameter is used to specify an external Python object to pass to the ufunc.
Let’s see some examples of how to use these ufuncs in NumPy.
Calculate the sinh value of 60 degrees:
Example: 
Check out the cosh value of pi/2:
Example: 
Insert the values in angle_arr array, then calculate the sinh value of each value:
Example: 
Provide negative angles in the below array, then check its cosh value:
Example: 
Calculating angles using hyperbolic sine, cosine, and tan. For example, the inverses of sinh, cosh, and tanh (arcsinh, arccosh, arctanh).
Implement the arcsinh() function, then compute the angle of 2.3 in radians:
Example: 
Apply arccosh() function in the following example:
Example: 
Take the range_array, compute the angle for every cosh value:
Example: 
In the following array of tangent values, calculate the angle for each value:
Example: 
Example Explanation
The given code imports the numpy library as npy. It creates a one-dimensional numpy array value_arr containing four float numbers [0.28, 0.34, 0.57, 0.99].
Then it applies the arctanh function of numpy on the value_arr array and stores the output in a new variable mrx.
The arctanh function calculates the inverse hyperbolic tangent of the input values, which results in an array of the same shape as the input array.