to_dense

paddle.Tensor. to_dense ( self )
Notes:

This API is ONLY available in Dygraph mode

Convert the current SparseTensor(COO or CSR) to DenseTensor.

Returns

A DenseTensor

Return type

Tensor

Examples

>>> import paddle
>>> indices = [[0, 0, 1, 2, 2], [1, 3, 2, 0, 1]]
>>> values = [1, 2, 3, 4, 5]
>>> dense_shape = [3, 4]
>>> sparse_x = paddle.sparse.sparse_coo_tensor(paddle.to_tensor(indices, dtype='int64'), paddle.to_tensor(values, dtype='float32'), shape=dense_shape)
>>> dense_x = sparse_x.to_dense()
>>> print(dense_x)
Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
[[0., 1., 0., 2.],
 [0., 0., 3., 0.],
 [4., 5., 0., 0.]])