# mlx.utils.tree_flatten — MLX 0.0.7 documentation

Skip to main content
`Ctrl`+`K`

# mlx.utils.tree_flatten

mlx.utils.tree_flatten(tree, prefix='', is_leaf=None)

  Flattens a python tree to a list of key, value tuples.

  The keys are using the dot notation to define trees of arbitrary depth and complexity.

      from mlx.utils import tree_flatten

      print(tree_flatten([[[0]]]))
      # [("0.0.0", 0)]

      print(tree_flatten([[[0]]], ".hello"))
      # [("hello.0.0.0", 0)]

  Note

  Dictionaries should have keys that are valid python identifiers.

  Parameters:

    - tree (Any) – The python tree to be flattened.

    - prefix (str) – A prefix to use for the keys. The first character is always discarded.

    - is_leaf (Callable) – An optional callable that returns True if the passed object is considered a leaf or False otherwise.

  Returns:

    The flat representation of the python tree.

  Return type:

    List[Tuple[str, Any]]