mindspore.ops.csr_inv

mindspore.ops.csr_inv(x: CSRTensor)[source]

Computes Reciprocal of input CSRTensor element-wise.

\[out_i = \frac{1}{x_{i} }\]
Parameters

x (CSRTensor) – Input CSRTensor. Must be one of the following types: float16, float32 or int32.

Returns

CSRTensor, has the same type and shape as input shape value.

Raises
  • TypeError – If x is not a CSRTensor.

  • TypeError – If dtype of x is not one of float16, float32, int32.

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_inv(x)
>>> print(output.values)
[-1.   0.5]