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
广告

© . All rights reserved.