NumPy参考 >例行程序 >Mathematical functions > numpy.tanh
numpy.
tanh
(X,/,出=无,*,其中=真,铸造= 'same_kind' ,为了= 'K' ,D型细胞=无,subok =真[,签名,extobj ] )= <ufunc '的tanh'> ¶计算双曲正切元素。
等同于np.sinh(x)/np.cosh(x)
或。-1j * np.tan(1j*x)
输入数组。
结果存储的位置。如果提供,它必须具有输入广播到的形状。如果未提供或没有,则返回一个新分配的数组。元组(只能作为关键字参数)的长度必须等于输出的数量。
此条件通过输入广播。在条件为True的位置,将out数组设置为ufunc结果。在其他地方,out数组将保留其原始值。请注意,如果通过default创建未初始化的out数组out=None
,则条件为False的数组中的
位置将保持未初始化。
有关其他仅关键字的参数,请参见 ufunc docs。
相应的双曲正切值。如果x是标量,则这是标量。
笔记
如果提供了out,则函数将结果写入其中,并返回对out的引用。(请参见示例)
参考文献
M. Abramowitz和IA Stegun,《数学函数手册》。纽约,纽约:多佛(Dover),1972年,第3页。83. http://www.math.sfu.ca/~cbm/aands/
Wikipedia,“双曲函数”, https://en.wikipedia.org/wiki/Hyperbolic_function
例子
>>> np.tanh((0, np.pi*1j, np.pi*1j/2))
array([ 0. +0.00000000e+00j, 0. -1.22460635e-16j, 0. +1.63317787e+16j])
>>> # Example of providing the optional output parameter illustrating
>>> # that what is returned is a reference to said parameter
>>> out1 = np.array([0], dtype='d')
>>> out2 = np.tanh([0.1], out1)
>>> out2 is out1
True
>>> # Example of ValueError due to provision of shape mis-matched `out`
>>> np.tanh(np.zeros((3,3)),np.zeros((2,2)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: operands could not be broadcast together with shapes (3,3) (2,2)