mindspore.ops.dense_to_sparse_coo

mindspore.ops.dense_to_sparse_coo(tensor)[source]

Convert a Tensor to COOTensor.

Note

Only 2-D tensor is supported for now.

Parameters

tensor – A dense tensor, must be 2-D.

Returns

indices: the positions of all non-zero values of the input. values: the non-zero values of the dense tensor. shape: the shape of the coo_tensor, length is 2.

Return type

COOTensor, a 2-D coo_tensor, containing

Raises
Supported Platforms:

GPU

Examples

>>> from mindspore import Tensor
>>> import mindspore as ms
>>> x = Tensor([[1, 0], [-5, 0]], ms.float32)
>>> output = ops.dense_to_sparse_coo(x)
>>> print(output)