用 Python 计算双曲正切
要计算双曲正切,在 Python Numpy 中使用 numpy.tanh() 方法。等同于 np.sinh(x)/np.cosh(x) 或 -1j * np.tan(1j*x)。返回相应的双曲正切值。如果 x 是标量,则它是标量。第一个参数 x 是输入数组。第二个和第三个参数是可选的。
第二个参数是一个 ndarray,一个将结果存储其中的位置。如果提供此参数,则它必须具有输入广播到的形状。如果未提供或为 None,则返回一个新分配的数组。
第三个参数是在输入上广播的条件。在条件为 True 的位置,out 数组将被设置为 ufunc 结果。在其他位置,out 数组将保留其原始值。
步骤
首先,导入所需的库 −
import numpy as np
获取三角双曲正切。查找 tanh −
print("\nResult...",np.tanh(np.pi*1j))
查找 tanh 90 度 −
print("\nResult...",np.tanh(np.pi/2.))
查找 tanh 60 度 −
print("\nResult...",np.tanh(np.pi/3.))
查找 tanh 45 度 −
print("\nResult...",np.tanh(np.pi/4.))
查找 tanh 30 度 −
print("\nResult...",np.tanh(np.pi/6.))
查找 tanh 0 度 −
print("\nResult...",np.tanh(0))
示例
import numpy as np # To compute the Hyperbolic tangent, use the numpy.tanh() method in Python Numpy # Equivalent to np.sinh(x)/np.cosh(x) or -1j * np.tan(1j*x). # Returns the corresponding hyperbolic tangent values. This is a scalar if x is a scalar. print("Get the Trigonometric Hyperbolic tangent...") # find tanh print("\nResult...",np.tanh(np.pi*1j)) # finding tanh 90 degrees print("\nResult...",np.tanh(np.pi/2.)) # finding tanh 60 degrees print("\nResult...",np.tanh(np.pi/3.)) # finding tanh 45 degrees print("\nResult...",np.tanh(np.pi/4.)) # finding tanh 30 degrees print("\nResult...",np.tanh(np.pi/6.)) # finding tanh 0 degrees print("\nResult...",np.tanh(0))
Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.
输出
Get the Trigonometric Hyperbolic tangent... Result... -1.2246467991473532e-16j Result... 0.9171523356672744 Result... 0.7807144353592677 Result... 0.6557942026326724 Result... 0.4804727781564516 Result... 0.0
广告