tensorinv#
- class brainunit.linalg.tensorinv(a, ind=2, **kwargs)#
Compute the tensor inverse of an array.
SaiUnit implementation of
numpy.linalg.tensorinv().This computes the inverse of the
tensordot()operation with the sameindvalue. The resulting unit isa.unit ** -1.- Parameters:
- Returns:
out – Tensor inverse of shape
(*a.shape[ind:], *a.shape[:ind]). The resulting unit isa.unit ** -1.- Return type:
Array|ndarray|bool|number|bool|int|float|complex| saiunit.Quantity
See also
saiunit.linalg.tensorsolveSolve the tensor equation
a x = b.saiunit.linalg.tensordotCompute tensor dot product.
saiunit.linalg.invCompute the inverse of a square matrix.
Examples
>>> import saiunit as u >>> import jax >>> import jax.numpy as jnp >>> key = jax.random.key(1337) >>> x = jax.random.normal(key, shape=(2, 2, 4)) * u.second >>> xinv = u.linalg.tensorinv(x, 2) >>> xinv.shape (4, 2, 2) >>> xinv_x = u.linalg.tensordot(xinv, x, axes=2) >>> u.math.allclose(xinv_x, jnp.eye(4), atol=1e-4) Array(True, dtype=bool)