numpy.tanh#

numpy.tanh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'tanh'>#

逐元素计算双曲正切。

等价于 np.sinh(x)/np.cosh(x)-1j * np.tan(1j*x)

参数:
x类数组

输入数组。

outndarray、None 或由 ndarray 和 None 组成的元组,可选

存储结果的位置。如果提供,它必须具有与输入广播后的形状兼容的形状。如果未提供或为 None,则返回新分配的数组。元组(仅作为关键字参数可能)的长度必须等于输出的数量。

where类数组,可选

此条件将广播到输入上。在条件为 True 的位置,out 数组将设置为 ufunc 的结果。在其他位置,out 数组将保留其原始值。请注意,如果通过默认的 out=None 创建了一个未初始化的 out 数组,则其中条件为 False 的位置将保持未初始化。

**kwargs

有关其他仅限关键字的参数,请参见ufunc 文档

返回:
yndarray

对应的双曲正切值。如果 x 是一个标量,则这是一个标量。

备注

如果提供了 out,函数会将结果写入其中,并返回对 out 的引用。(参见示例)

参考文献

[1]

M. Abramowitz 和 I. A. Stegun,《数学函数手册》。纽约,NY:Dover,1972,第 83 页。 https://personal.math.ubc.ca/~cbm/aands/page_83.htm

[2]

维基百科,“双曲函数”,https://en.wikipedia.org/wiki/Hyperbolic_function

示例

>>> import numpy as np
>>> 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)