mindspore.nn.SparseToDense
- class mindspore.nn.SparseToDense[source]
- Converts a sparse tensor into dense. - In Python, for the ease of use, three tensors are collected into a SparseTensor class. MindSpore uses three independent dense tensors: indices, value and dense shape to represent the sparse tensor. Separate indexes, values and dense shape tensors can be wrapped in a Sparse Tensor object before being passed to the OPS below. - Inputs:
- sparse_tensor ( - mindspore.SparseTensor): the sparse tensor to convert.
 
- Outputs:
- Tensor, converted from sparse tensor. 
 - Raises
 - Supported Platforms:
- CPU
 - Examples - >>> import mindspore as ms >>> from mindspore import Tensor, SparseTensor >>> import mindspore.nn as nn >>> import mindspore.context as context >>> context.set_context(mode=context.PYNATIVE_MODE) >>> 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]]