Thursday, October 23, 2025
HomeLanguagesCompute the inverse hyperbolic tangent in Python

Compute the inverse hyperbolic tangent in Python

In this article, we will cover how to compute the inverse hyperbolic tangent in Python using NumPy.

numpy.emath.arctanh method

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)

Parameters

  • 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.

Example 1

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.

Python3




# import necessary packages
import numpy as np
  
# Create an input array
x = np.array([2, 3, 4])
  
# input array before computation
print("Input array->", x)
  
# compute the inverse hyperbolic tangent
# using arctanh method
print("Resultant Array->", np.emath.arctanh(x))


Output

Input array-> [2 3 4]

Resultant Array-> [0.54930614+1.57079633j 0.34657359+1.57079633j 0.25541281+1.57079633j]

Example 2

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.

Python3




# import necessary packages
import numpy as np
  
# Create an input array
x = np.array([1, -1])
  
# input array before computation
print("Input array->", x)
  
# compute the inverse hyperbolic tangent using
# arctanh method
print("Resultant Array->", np.emath.arctanh(x))


Output

Input array-> [ 1 -1]
Resultant Array-> [ inf -inf]

Example 3

Python3




# import necessary packages
import numpy as np
  
# Create an input array
x = np.array([-1, 0, 1, 5])
  
# input array before computation
print("Input array->", x)
  
# compute the inverse hyperbolic tangent 
# using arctanh method
print("Resultant Array->", np.emath.arctanh(x))


Output

Input array-> [-1  0  1  5]

Resultant Array-> [-inf+0.j    0.+0.j    inf+0.j

    0.20273255+1.57079633j]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS