mindspore.ops.csr_to_coo

View Source On Gitee
mindspore.ops.csr_to_coo(tensor: CSRTensor)[source]

Converts a CSRTensor to COOTensor.

Note

Only 2-D CSRTensor is supported for now.

Parameters

tensor (CSRTensor) – A CSRTensor, must be 2-D.

Returns

2D COOTensor, the input tensor stored in COO format.

Raises
Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import Tensor, CSRTensor
>>> indptr = Tensor([0, 1, 2]).astype("int32")
>>> indices = Tensor([0, 1]).astype("int32")
>>> values = Tensor([2, 1]).astype("float32")
>>> shape = (2, 4)
>>> x = CSRTensor(indptr, indices, values, shape)
>>> output = ops.csr_to_coo(x)
>>> print(output.indices)
[[0 0]
[1 1]]