tf.keras.tree.flatten_with_path

Flattens a possibly nested structure into a list.

This is a variant of flattens() which produces a list of pairs: (path, item). A path is a tuple of indices and/or keys which uniquely identifies the position of the corresponding item.

Dictionaries with non-sortable keys are not supported.

Examples:

keras.flatten_with_path([{"foo": 42}])
[((0, 'foo'), 42)]

structure An arbitrarily nested structure.

A list of (path, item) pairs corresponding to the flattened version of the input structure.