View source on GitHub |
Traverses the given nested structure, applying the given function.
tf.keras.tree.traverse(
func, structure, top_down=True
)
The traversal is depth-first. If top_down
is True (default), parents
are returned before their children (giving the option to avoid traversing
into a sub-tree).
Examples:
v = []
keras.tree.traverse(v.append, [(1, 2), [3], {"a": 4}], top_down=True)
[(1, 2), [3], {'a': 4}]
v
[[(1, 2), [3], {'a': 4}], (1, 2), 1, 2, [3], 3, {'a': 4}, 4]
v = []
keras.tree.traverse(v.append, [(1, 2), [3], {"a": 4}], top_down=False)
[(1, 2), [3], {'a': 4}]
v
[1, 2, (1, 2), 3, [3], 4, {'a': 4}, [(1, 2), [3], {'a': 4}]]
Returns | |
---|---|
The structured output from the traversal. |