# tf.sparse.from_dense

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/sparse/from_dense) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/ops/sparse_ops.py#L104-L124) |

Converts a dense tensor into a sparse tensor.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.sparse.from_dense`](https://www.tensorflow.org/api_docs/python/tf/sparse/from_dense)

<br />

    tf.sparse.from_dense(
        tensor, name=None
    )

Only elements not equal to zero will be present in the result. The resulting
`SparseTensor` has the same dtype and shape as the input.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `tensor` | A dense `Tensor` to be converted to a `SparseTensor`. |
| `name` | Optional name for the op. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The `SparseTensor`. ||

<br />