Python - AI 助手

Python cmath.atanh() 函式



Python cmath.atanh() 函式返回反雙曲正切。

反雙曲正切表示為 tanh-1(x) 或也稱為 artanh(x),其中這是一個數學函式,獲取其雙曲正切值為給定數字 x 的值。

這個函式也可以用其他方式解釋;如果我們有 -1 到 1 之間的值,那麼這個函式將返回一個等於 x 的雙曲正切值。

反雙曲正切函式的每個域都限制在範圍 (-1,1) 內。反雙曲正切始終會輸出一個實數。

語法

以下是 Python cmath.atanh() 函式的基本語法 -

cmath.atanh(x)

引數

此函式接受範圍為 (-1,1) 的域作為引數,我們需要為其找到反雙曲正切。

返回值

此函式返回範圍為 (-∞,∞) 內的反雙曲正切。

示例 1

0 的雙曲正切為 0。當我們將 0 作為引數傳遞時,此 Python cmath.atanh() 函式將返回 0j。

import cmath
x = 0
result = cmath.atanh(x)
print(result)

輸出

當我們執行以上程式碼時,它會產生以下結果 -

0j

示例 2

當我們將分數值傳遞給此 cmath.atanh() 函式時,它會返回一個實數。

import cmath
from fractions import Fraction
x = Fraction(1, -7)
result = cmath.atanh(x)
print(result)

輸出

獲得的輸出如下 -

(-0.14384103622589042+0j)

示例 3

在下面的示例中,我們使用cmath.atanh()函式獲取一個負數的反雙曲正切值。

import cmath
x = -0.65
result = cmath.atanh(x)
print(result)

輸出

以下是上述程式碼的輸出:

(-0.7752987062055835+0j)
python_modules.htm
廣告