mindspore.Tensor.tanh

Tensor.tanh()[source]

Tanh activation function.

Computes hyperbolic tangent of self Tensor element-wise. The Tanh function is defined as:

tanh(xi)=exp(xi)exp(xi)exp(xi)+exp(xi)=exp(2xi)1exp(2xi)+1,

where xi is an element of the self Tensor.

Returns

Tensor, with the same dtype and shape as self.

Raises

TypeError – If dtype of self tensor is not float16, float32, float64, complex64 or complex128.

Supported Platforms:

Ascend GPU CPU

Examples

>>> input_x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)
>>> output = input_x.tanh()
>>> print(output)
[0.7615941 0.9640276 0.9950547 0.9993293 0.9999092]