mindspore.Tensor.tanh

Tensor.tanh() Tensor

Computes hyperbolic tangent of self 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 input Tensor.

Tanh Activation Function Graph:

../../../_images/Tanh.png
Returns

Tensor, with the same type and shape as the self.

Raises

TypeError – If self is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

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