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: 

import numpy as npy mrx = npy.sinh(npy.pi/6) # pi/6 is equal to 30 degrees print(mrx)

Check out the cosh value of pi/2:

Example: 

import numpy as npy mrx = npy.cosh(npy.pi/2) # pi/2 is equal to 90 degrees print(mrx)

Insert the values in angle_arr array, then calculate the sinh value of each value:

Example: 

import numpy as npy angle_arr = npy.array([npy.pi/2, npy.pi/3, npy.pi/4, npy.pi/5, npy.pi/6, npy.pi/7]) mrx = npy.sinh(angle_arr) print(mrx)

Provide negative angles in the below array, then check its cosh value:

Example: 

import numpy as npy neg_angle_arr = npy.array([npy.pi/-2, npy.pi/-3, npy.pi/-4, npy.pi/-5, npy.pi/-6, npy.pi/-7]) mrx = npy.cosh(neg_angle_arr) print(mrx)

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: 

import numpy as npy mrx = npy.arcsinh(2.3) print(mrx)

Apply arccosh() function in the following example:

Example: 

import numpy as npy mrx = npy.arccosh(11.59) print(mrx)

Take the range_array, compute the angle for every cosh value:

Example: 

import numpy as npy value_arr = npy.array([1.5, 2.3, 3.3, 4.7]) mrx = npy.arccosh(value_arr) print(mrx)

In the following array of tangent values, calculate the angle for each value:

Example: 

import numpy as npy value_arr = npy.array([0.28, 0.34, 0.57, 0.99]) mrx = npy.arctanh(value_arr) print(mrx)

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.

We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *