mindspore.ops.dense_to_sparse_csr

mindspore.ops.dense_to_sparse_csr(tensor)[source]

Convert a Tensor to CSRTensor.

Note

Only 2-D tensor is supported for now.

Parameters

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

Returns

indptr: indicates the start and end point for values in each row. indices: the column positions of all non-zero values of the input. values: the non-zero values of the dense tensor. shape: the shape of the csr_tensor, length is 2.

Return type

CSRTensor, a 2-D csr_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_csr(x)
>>> print(output)