Compute the inverse hyperbolic tangent with scimath in Python
The inverse hyperbolic tangent is also called as arctanh or tanh-1. To compute the inverse hyperbolic tangent Python provides a method called arctanh which is present in numpy.emath package. arctanh method accepts an array of numbers that may be real, complex, and returns the principal value of arctanh(x). The output of the arctanh method depends on the input array elements. If x=1 then it returns Infinity. If x=-1 then it returns -Infinity. If the absolute value of x is greater than 1 i.e., abs(x)>1, or for complex numbers, a result is always a complex number. Below is the syntax of emath.arctanh.
Syntax: numpy.emath.arctanh(x, out=None)
- x- It is an input array.
- out- It specifies the location into which result is stored. It is an optional parameter.
Returns an array of the same shape as input array x. Resultant array consists principal values.
In the below code we passed an input array consisting of values >1 to the arctanh method. As all the abs(x)>1 the arctanh method returns array of complex numbers.
Input array-> [2 3 4]
Resultant Array-> [0.54930614+1.57079633j 0.34657359+1.57079633j 0.25541281+1.57079633j]
Here we passed an input array consisting 1,-1 to arctanh method. For the values of 1,-1 arctanh method returns Infinity and -Infinity values as a result respectively.
Input array-> [ 1 -1] Resultant Array-> [ inf -inf]
Input array-> [-1 0 1 5]
Resultant Array-> [-inf+0.j 0.+0.j inf+0.j