numpy.tanh

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

计算双曲正切元。

相当于 np.sinh(x)/np.cosh(x)-1j * np.tan(1j*x) .

参数
xarray_like

输入数组。

outndarray、none或ndarray和none的元组,可选

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

where阵列式,可选

这种情况通过输入广播。在条件为真的位置 out 数组将被设置为ufunc结果。在其他地方 out 数组将保留其原始值。请注意,如果未初始化 out 数组是通过默认值创建的 out=None ,其中条件为False的位置将保持未初始化状态。

**kwargs

有关其他仅限关键字的参数,请参见 ufunc docs .

返回
y恩达雷

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

笔记

如果 out 提供,函数将结果写入其中,并返回对 out . (见例子)

工具书类

1

M.Abramowitz和I.A.Stegun,《数学函数手册》。纽约,纽约:多佛,1972年,第83页。http://www.math.sfu.ca/~cbm/aands/

2

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

实例

>>> 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)