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
)
| Used in the guide | Used in the tutorials |
|---|---|
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)
sp_input
SparseTensor.
default_value
sp_input. Defaults to zero.
validate_indices
True, indices are checked to make
sure they are sorted in lexicographic order and that there are no repeats.
name
sp_input.dense_shape and values specified by
the non-empty values in sp_input. Indices not in sp_input are assigned
default_value.
TypeError
sp_input is not a SparseTensor.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.