# tf.nest.flatten

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nest/flatten) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/util/nest.py#L231-L262) |

Returns a flat list from a given nested structure.

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.nest.flatten(
        structure, expand_composites=False
    )

If nest is not a sequence, tuple, or dict, then returns a single-element list:
\[nest\].

In the case of dict instances, the sequence consists of the values, sorted by
key to ensure deterministic behavior. This is true also for OrderedDict
instances: their sequence order is ignored, the sorting order of keys is used
instead. The same convention is followed in pack_sequence_as. This correctly
repacks dicts and OrderedDicts after they have been flattened, and also allows
flattening an OrderedDict and then repacking it back using a corresponding
plain dict, or vice-versa. Dictionaries with non-sortable keys cannot be
flattened.

Users must not modify any collections used in nest while this function is
running.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `structure` | an arbitrarily nested structure or a scalar object. Note, numpy arrays are considered scalars. |
| `expand_composites` | If true, then composite tensors such as tf.SparseTensor and tf.RaggedTensor are expanded into their component tensors. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A Python list, the flattened version of the input. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | The nest is or contains a dict with non-sortable keys. |

<br />