mars.tensor.tanh#
- mars.tensor.tanh(x, out=None, where=None, **kwargs)[来源]#
 逐元素计算双曲正切。
等价于
mt.sinh(x)/np.cosh(x)或-1j * mt.tan(1j*x)。- Parameters
 x (array_like) – 输入张量。
out (Tensor, None, 或 tuple 的 Tensor 和 None, 可选) – 结果存储的位置。如果提供,它必须具有和输入相同的广播形状。如果未提供或None,将返回一个新分配的张量。元组(仅作为关键字参数可能)必须具有与输出数量相等的长度。
where (array_like, 可选) – 值为 True 表示在该位置计算 ufunc,值为 False 表示保持输出中的该值不变。
**kwargs –
- Returns
 y – 相应的双曲正切值。
- Return type
 张量
备注
如果 out 被提供,函数将结果写入其中,并返回对 out 的引用。 (参见示例)
参考文献
- 1
 M. Abramowitz 和 I. A. Stegun, 数学函数手册。 纽约, NY: Dover, 1972, 第83页。 http://www.math.sfu.ca/~cbm/aands/
- 2
 维基百科,“双曲函数”, http://en.wikipedia.org/wiki/Hyperbolic_function
示例
>>> import mars.tensor as mt
>>> mt.tanh((0, mt.pi*1j, mt.pi*1j/2)).execute() 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 = mt.zeros(1) >>> out2 = mt.tanh([0.1], out1) >>> out2 is out1 True
>>> # Example of ValueError due to provision of shape mis-matched `out` >>> mt.tanh(mt.zeros((3,3)),mt.zeros((2,2))) Traceback (most recent call last): ... ValueError: operands could not be broadcast together with shapes (3,3) (2,2)