mindspore.mint.nn.Tanh
- class mindspore.mint.nn.Tanh[source]
Apply the Tanh function element-wise.
Tanh function is defined as:
\[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},\]where \(x_i\) is an element of the input tensor.
Tanh Activation Function Graph:
- Inputs:
input (Tensor) - The input tensor. Data type must be mindspore.float16 or mindspore.float32.
- Outputs:
Tensor.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> input = mindspore.tensor([1, 2, 3, 2, 1], mindspore.float16) >>> tanh = mindspore.mint.nn.Tanh() >>> output = tanh(input) >>> print(output) [0.7617 0.964 0.995 0.964 0.7617]