braintools.tree.shift#
- braintools.tree.shift(tree1, x, is_leaf=<function is_quantity>)[source]#
Add a value to every leaf array in a PyTree.
- Parameters:
- Returns:
PyTree with each leaf shifted by x.
- Return type:
PyTree
Examples
>>> import jax.numpy as jnp >>> import braintools >>> tree = {'a': jnp.array([1.0, 2.0]), 'b': jnp.array([3.0])} >>> out = braintools.tree.shift(tree, 1.0) >>> {k: v.tolist() for k, v in out.items()} {'a': [2.0, 3.0], 'b': [4.0]}