braintools.tree.as_numpy

Contents

braintools.tree.as_numpy#

braintools.tree.as_numpy(tree, is_leaf=<function is_quantity>)[source]#

Convert all leaves of a PyTree to NumPy arrays.

Parameters:
  • tree (Quantity]) – Input PyTree whose leaves will be converted.

  • is_leaf (Callable[[Any], bool] | None) – Predicate to treat a node as a leaf during traversal. Defaults to u.math.is_quantity.

Returns:

PyTree with np.asarray applied to each leaf.

Return type:

ndarray]

Notes

This performs a best-effort conversion using np.asarray; for JAX arrays this typically results in host NumPy arrays.