archimedes.tree.structureΒΆ
- archimedes.tree.structure(tree: Tree, is_leaf: Callable[[Any], bool] | None = None) TreeDefΒΆ
Extract the structure of a tree without the leaf values.
Returns a
TreeDefthat describes the structure of the tree, which can be used withtree_unflattento reconstruct a tree with new leaf values.- Parameters:
tree (Tree) β A tree whose structure is to be determined.
is_leaf (callable, optional) β A function that takes a tree node as input and returns a boolean indicating whether it should be considered a leaf.
- Returns:
treedef β A tree definition that describes the structure of the input tree.
- Return type:
TreeDef
See also
tree_flattenFlatten a tree into a list of leaves and a treedef
tree_unflattenReconstruct a tree from leaves and a treedef