mindspore.ops.coo_tanh

View Source On Gitee
mindspore.ops.coo_tanh(x: COOTensor)[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 COOTensor.

Parameters

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

Returns

COOTensor, 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 COOTensor.

Supported Platforms:

Ascend GPU CPU

Examples

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