mindspore.mint.nn.Tanh
- class mindspore.mint.nn.Tanh[source]
Applies the Tanh function element-wise, returns a new tensor with the hyperbolic tangent of the elements of input.
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:
Warning
This is an experimental API that is subject to change or deletion.
- Inputs:
input (Tensor) - Tensor of any dimension, input with data type of float16 or float32.
- Outputs:
Tensor, with the same type and shape as the input.
- Raises
TypeError – If dtype of input is neither float16 nor float32.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> from mindspore import Tensor, mint >>> import numpy as np >>> input = Tensor(np.array([1, 2, 3, 2, 1]), mindspore.float16) >>> tanh = mint.nn.Tanh() >>> output = tanh(input) >>> print(output) [0.7617 0.964 0.995 0.964 0.7617]