braintools.tree.sub#
- braintools.tree.sub(tree1, tree2, is_leaf=<function is_quantity>)[source]#
Elementwise subtraction of two PyTrees.
- Parameters:
- Returns:
PyTree where each leaf is tree1 - tree2 elementwise.
- Return type:
PyTree
Examples
>>> import jax.numpy as jnp >>> import braintools >>> tree = {'a': jnp.array([1.0, 2.0]), 'b': jnp.array([3.0])} >>> other = {'a': jnp.array([10.0, 20.0]), 'b': jnp.array([30.0])} >>> out = braintools.tree.sub(other, tree) >>> {k: v.tolist() for k, v in out.items()} {'a': [9.0, 18.0], 'b': [27.0]}