# tf.sparse.to_dense

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/sparse/to_dense) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/sparse_ops.py#L1446-L1498) |

Converts a `SparseTensor` into a dense tensor.

#### View aliases


**Main aliases**

\`tf.sparse_tensor_to_dense\`
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.sparse.to_dense`](https://www.tensorflow.org/api_docs/python/tf/sparse/to_dense), [`tf.compat.v1.sparse_tensor_to_dense`](https://www.tensorflow.org/api_docs/python/tf/sparse/to_dense), \`tf.compat.v2.sparse.to_dense\`

<br />

    tf.sparse.to_dense(
        sp_input, default_value=None, validate_indices=True, name=None
    )

This op is a convenience wrapper around `sparse_to_dense` for `SparseTensor`s.

For example, if `sp_input` has shape `[3, 5]` and non-empty string values:

    [0, 1]: a
    [0, 3]: b
    [2, 0]: c

and `default_value` is `x`, then the output will be a dense `[3, 5]`
string tensor with values:

    [[x a x b x]
     [x x x x x]
     [c x x x x]]

Indices must be without repeats. This is only
tested if `validate_indices` is `True`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `sp_input` | The input `SparseTensor`. |
| `default_value` | Scalar value to set for indices not specified in `sp_input`. Defaults to zero. |
| `validate_indices` | A boolean value. If `True`, indices are checked to make sure they are sorted in lexicographic order and that there are no repeats. |
| `name` | A name prefix for the returned tensors (optional). |

<br />

<br />

<br />

<br />

| ## 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`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `sp_input` is not a `SparseTensor`. |

<br />