mindspore.ops.csr_tanh

查看源文件
mindspore.ops.csr_tanh(x: CSRTensor)[源代码]

逐元素计算CSRTensor输入元素的双曲正切。Tanh函数定义为:

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

其中 xi 是输入CSRTensor的元素。

参数:
  • x (CSRTensor) - Tanh的输入,任意维度的CSRTensor,其数据类型为float16或float32。

返回:

CSRTensor,数据类型和shape与 x 相同。

异常:
  • TypeError - x 的数据类型既不是float16也不是float32。

  • TypeError - x 不是CSRTensor。

支持平台:

Ascend GPU CPU

样例:

>>> 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]