maxframe.tensor.tanh#
- maxframe.tensor.tanh(x, out=None, where=None, **kwargs)[源代码]#
逐元素计算双曲正切值。
等价于
mt.sinh(x)/np.cosh(x)或-1j * mt.tan(1j*x)。- 参数:
x (array_like) -- 输入张量。
out (Tensor, None, or tuple of Tensor and None, optional) -- 用于存储结果的位置。如果提供,它必须具有与输入广播兼容的形状。如果未提供或为 None,则返回一个新分配的张量。元组(仅能作为关键字参数)的长度必须等于输出的数量。
where (array_like, optional) -- 值为 True 表示在该位置计算 ufunc,值为 False 表示保留输出中的值不变。
**kwargs
- 返回:
y -- 对应的双曲正切值。
- 返回类型:
Tensor
备注
如果提供了 out,函数会将结果写入其中,并返回对 out 的引用。(参见示例)
引用
示例
>>> import maxframe.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: operators could not be broadcast together with shapes (3,3) (2,2)