jax.tree.leaves_with_path#
- jax.tree.leaves_with_path(tree, is_leaf=None, is_leaf_takes_path=False)[source]#
Gets the leaves of a pytree like
tree_leavesand returns each leaf’s key path.- Parameters:
- Returns:
A list of key-leaf pairs, each of which contains a leaf and its key path.
- Return type:
Examples
>>> import jax >>> jax.tree.leaves_with_path([1, {'x': 3}]) [((SequenceKey(idx=0),), 1), ((SequenceKey(idx=1), DictKey(key='x')), 3)]