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}]]
| Args | 
|---|
| func | The function to be applied to each sub-nest of the structure. When traversing top-down:
    If func(subtree) is Nonethe traversal continues into the
    sub-tree.
    Iffunc(subtree) is not Nonethe traversal does not continue
    into the sub-tree. The sub-tree will be replaced byfunc(subtree)in the returned structure (to replace the sub-tree withNone, use
    the special value_MAP_TO_NONE). When traversing bottom-up:
    If func(subtree) is Nonethe traversed sub-tree is returned
    unaltered.
    Iffunc(subtree) is not Nonethe sub-tree will be replaced byfunc(subtree)in the returned structure (to replace the sub-tree
    with None, use the special value_MAP_TO_NONE). | 
| structure | The structure to traverse. | 
| top_down | If True, parent structures will be visited before their
children. | 
| Returns | 
|---|
| The structured output from the traversal. |