to_sparse_coo

paddle.Tensor. to_sparse_coo ( self, sparse_dim )
Notes:

This API is ONLY available in Dygraph mode

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/dygraph/tensor_patch_methods.py:docstring of paddle.fluid.dygraph.tensor_patch_methods.monkey_patch_tensor.<locals>.to_sparse_coo, line 3)

Definition list ends without a blank line; unexpected unindent.

Convert the current DenseTensor to SparseTensor in COO format.

Returns

A SparseCooTensor

Return type

Tensor

Examples

import paddle
dense_x = [[0, 1, 0, 2], [0, 0, 3, 4]]
dense_x = paddle.to_tensor(dense_x, dtype='float32')
sparse_x = dense_x.to_sparse_coo(sparse_dim=2)
#indices=[[0, 0, 1, 1],
#         [1, 3, 2, 3]],
#values=[1., 2., 3., 4.]