tf.keras.tree.flatten | TensorFlow v2.16.1 (original) (raw)
tf.keras.tree.flatten
Stay organized with collections Save and categorize content based on your preferences.
Flattens a possibly nested structure into a list.
tf.keras.tree.flatten(
structure
)
In the case of dict instances, the sequence consists of the values, sorted by key to ensure deterministic behavior. This is true also forcollections.OrderedDict
instances: their sequence order is considered. The same convention is followed in unflatten_as
. This correctly unflattens dicts and OrderedDict
after they have been flattened, or vice-versa.
Dictionaries with non-sortable keys cannot be flattened.
Examples:
keras.tree.flatten([[1, 2, 3], [4, [5], [[6]]]])
[1, 2, 3, 4, 5, 6]
keras.tree.flatten(None)
[None]
keras.tree.flatten(1)
[1]
keras.tree.flatten({100: 'world!', 6: 'Hello'})
['Hello', 'world!']
Args | |
---|---|
structure | An arbitrarily nested structure. |
Returns |
---|
A list, the flattened version of the input structure. |