mindspore.nn.SparseToDense

class mindspore.nn.SparseToDense[source]

Convert a sparse tensor into dense.

Not yet supported by any backend at the moment.

Parameters

sparse_tensor (SparseTensor) – the sparse tensor to convert.

Returns

Tensor, the tensor converted.

Supported Platforms:

CPU

Examples

>>> import mindspore as ms
>>> from mindspore import Tensor, SparseTensor
>>> import mindspore.nn as nn
>>> indices = Tensor([[0, 1], [1, 2]])
>>> values = Tensor([1, 2], dtype=ms.int32)
>>> dense_shape = (3, 4)
>>> sparse_tensor = SparseTensor(indices, values, dense_shape)
>>> sparse_to_dense = nn.SparseToDense()
>>> result = sparse_to_dense(sparse_tensor)
>>> print(result)
[[0 1 0 0]
 [0 0 2 0]
 [0 0 0 0]]