mindspore.ops.tanh

查看源文件
mindspore.ops.tanh(input)[源代码]

逐元素计算输入tensor的双曲正切。Tanh函数定义为:

\[tanh(x_i) = \frac{\exp(x_i) - \exp(-x_i)}{\exp(x_i) + \exp(-x_i)} = \frac{\exp(2x_i) - 1}{\exp(2x_i) + 1}\]

其中 \(x_i\) 是输入tensor的元素。

Tanh函数图:

../../_images/Tanh.png
参数:
  • input (Tensor) - 输入tensor。

返回:

Tensor,数据类型和shape与 input 相同。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> import numpy as np
>>> input = mindspore.tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
>>> output = mindspore.ops.tanh(input)
>>> print(output)
[0.7615942 0.9640276 0.9950548 0.9993293 0.9999092]