Python atanh

Python 的 atanh 函数用于计算指定表达式或数字的双曲反正切值。atanh 函数也称为双曲正切函数的反函数。

在本节中,我们将讨论如何在 Python 编程语言中使用 atanh 函数,并提供一个示例。atanh 函数的语法是:

math.atanh(number);

数字:用于查找双曲反正切值的有效数值表达式。

  • 如果数字参数为正数或负数,atanh 函数将返回双曲反正切值。
  • 如果它不在 -1(不包含)和 1(不包含)之间,则返回 ValueError。
  • 如果它不是数字,则返回 TypeError。

Python atanh 函数示例

atanh 函数允许您查找数值的双曲反正切值。在此示例中,我们将查找不同数据类型的双曲反正切值。

import math

Tup = (0.10, 0.20, 0.35, -0.45 , 0.75)
Lis = [-0.15, 0.25, -0.32, -0.95 , 0.64]

print('Hyperbolic Arc Tangent of Positive Number = %.2f' %math.atanh(0.91))
print('Hyperbolic Arc Tangent of Negative Number = %.2f' %math.atanh(-0.91))

print('Hyperbolic Arc Tangent of Tuple Item = %.2f' %math.atanh(Tup[3]))
print('Hyperbolic Arc Tangent of List Item = %.2f' %math.atanh(Lis[2]))

print('Hyperbolic Arc Tangent of Multiple Numbers = %.2f' %math.atanh(0.22 + 0.49 - 0.27))

print('Hyperbolic Arc Tangent of String Value = ', math.atanh('Hello'))
Python ATANH Function Example

首先,我们直接对正数和负数都使用了它。以下语句计算了相应值的双曲反正切。

print('Hyperbolic Arc Tangent of Positive Number = %.2f' %math.atanh(0.91))
print('Hyperbolic Arc Tangent of Negative Number = %.2f' %math.atanh(-0.91))

提示:您可以尝试大于或等于 1 的值,但这会引发 ValueError。请参考 tan 以了解正切函数。

接下来,我们在 元组列表项上使用了 atanh 函数。请参见上面的 Python 屏幕截图,此 数学函数在它们上面可以完美运行。

print('Hyperbolic Arc Tangent of Tuple Item = %.2f' %math.atanh(Tup[3]))
print('Hyperbolic Arc Tangent of List Item = %.2f' %math.atanh(Lis[2]))

接下来,我们直接对多个值使用了 atanh 方法。

print('Hyperbolic Arc Tangent of Multiple Numbers = %.2f' %math.atanh(0.22 + 0.49 - 0.27))

我们尝试了一个字符串值,它返回了 TypeError 作为输出。

print('Hyperbolic Arc Tangent of String Value = ', math.atanh('Hello'))