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:
- Returns:
PyTree with
np.asarrayapplied 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.Examples
>>> import jax.numpy as jnp >>> import braintools >>> tree = {'a': jnp.array([1.0, 2.0]), 'b': jnp.array([3.0])} >>> out = braintools.tree.as_numpy(tree) >>> type(out['a']).__name__, out['b'].tolist() ('ndarray', [3.0])