Compute the inverse Hyperbolic tangent in Python

PythonNumpyServer Side ProgrammingProgramming

The arctanh is a multivalued function: for each x there are infinitely many numbers z such that tanh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2]. The inverse hyperbolic tangent is also known as atanh or tanh^-1.

To compute the inverse Hyperbolic tangent, use the numpy.arctanh() method. The method returns the array of the same shape as x. This is a scalar if x is a scalar. The 1st parameter, x is input array. The 2nd and 3rd parameters are optional.

The 2nd parameter is an ndarray, A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.

The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value.

Steps

At first, import the required libraries −

import numpy as np

Find arctanh 0 −

print("\nResult...",np.arctanh(0))

Finding arctanh 0.3 −

print("\nResult...",np.arctanh(0.3))

Finding arctanh -0.3 −

print("\nResult...",np.arctanh(-0.3))

Finding arctanh 0.5 −

print("\nResult...",np.arctanh(0.5))

Finding arctanh 0.11 −

print("\nResult...",np.arctanh(0.11))

Example

import numpy as np

# The arctanh is a multivalued function: for each x there are infinitely many numbers z such that tanh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2].
# The inverse hyperbolic tangent is also known as atanh or tanh^-1.
print("Get the Trigonometric inverse Hyperbolic tangent...")

# find arctanh 0
print("\nResult...",np.arctanh(0))

# finding arctanh 0.3
print("\nResult...",np.arctanh(0.3))

# finding arctanh -0.3
print("\nResult...",np.arctanh(-0.3))

# finding arctanh 0.5
print("\nResult...",np.arctanh(0.5))

# finding arctanh 0.11
print("\nResult...",np.arctanh(0.11))

Output

Get the Trigonometric inverse Hyperbolic tangent...

Result... 0.0

Result... 0.30951960420311175

Result... -0.30951960420311175

Result... 0.5493061443340548

Result... 0.11044691579009715
raja
Updated on 28-Feb-2022 09:14:48

Advertisements