apply_func_to_leaf_subtrees =========================== .. py:function:: t3toolbox.backend.stacking.apply_func_to_leaf_subtrees(tree, func, leaf_structure) .. code-block:: python def apply_func_to_leaf_subtrees( tree, # nested tuples; each leaf is itself a subtree shaped like leaf_structure func: typ.Callable, # applied to each leaf-subtree leaf_structure, # nested-tuple template defining what counts as one leaf ): Apply a function to all "leafs" in a tree. A "leaf" is, itself, a subtree with the structure given in leaft_structure. .. rubric:: Examples >>> import numpy as np >>> import t3toolbox.backend.stacking as stacking >>> func = lambda x: (x[0] - x[1][0], x[0] + x[1][1]) # (a,(b,c)) -> (a-b, a+c) >>> LS = (None, (None, None)) >>> T1 = (1, (2, 3)) >>> T2 = (4, (5, 6)) >>> T3 = (7, (8, 9)) >>> T = ((T1, T2), ((T3,),)) >>> print(stacking.apply_func_to_leaf_subtrees(T, func, LS)) (((-1, 4), (-1, 10)), (((-1, 16),),))