archimedes.tree.unflattenยถ
- archimedes.tree.unflatten(treedef: TreeDef, xs: list[ArrayLike]) Treeยถ
Reconstruct a tree from a list of leaves and a treedef.
This function is the inverse of
tree_flatten. It takes a list of leaf values and a tree definition, and reconstructs the original tree structure.- Parameters:
treedef (TreeDef) โ A tree definition, typically produced by
tree_flattenortree_structure.xs (list[ArrayLike]) โ A list of leaf values to be placed in the reconstructed tree. The length must match the number of leaves in
treedef.
- Returns:
tree โ The reconstructed tree with the same structure as defined by treedef and with leaf values from
xs.- Return type:
Tree
- Raises:
ValueError โ If the number of leaves in
xsdoesnโt match the expected number intreedef.
See also
tree_flattenFlatten a tree into a list of leaves and a treedef
tree_structureExtract just the structure from a tree