View source on GitHub
|
Converts a SparseTensor into a dense tensor.
tf.sparse.to_dense(
sp_input, default_value=None, validate_indices=True, name=None
)
For this sparse tensor with three non-empty values:
sp_input = tf.sparse.SparseTensor(dense_shape=[3, 5],values=[7, 8, 9],indices =[[0, 1],[0, 3],[2, 0]])
The output will be a dense [3, 5] tensor with values:
tf.sparse.to_dense(sp_input).numpy()array([[0, 7, 0, 8, 0],[0, 0, 0, 0, 0],[9, 0, 0, 0, 0]], dtype=int32)
Returns | |
|---|---|
A dense tensor with shape sp_input.dense_shape and values specified by
the non-empty values in sp_input. Indices not in sp_input are assigned
default_value.
|
Raises | |
|---|---|
TypeError
|
If sp_input is not a SparseTensor.
|
View source on GitHub