mindspore.ops.csr_tanh

View Source On Gitee
mindspore.ops.csr_tanh(x: CSRTensor)[source]

Computes hyperbolic tangent of input element-wise. The 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 CSRTensor.

Parameters

x (CSRTensor) – Input CSRTensor, with float16 or float32 data type.

Returns

CSRTensor, with the same type and shape as the x.

Raises
  • TypeError – If dtype of x is neither float16 nor float32.

  • TypeError – If x is not a CSRTensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import dtype as mstype
>>> from mindspore import Tensor, ops, CSRTensor
>>> indptr = Tensor([0, 1, 2, 2], dtype=mstype.int32)
>>> indices = Tensor([3, 0], dtype=mstype.int32)
>>> values = Tensor([-1, 2], dtype=mstype.float32)
>>> shape = (3, 4)
>>> x = CSRTensor(indptr, indices, values, shape)
>>> output = ops.csr_tanh(x)
>>> print(output.values)
[-0.7615942  0.9640276]