bundles / numpy 2.4.4 / numpy / linalg / tensorinv
_ArrayFunctionDispatcher
numpy.linalg:tensorinv
source: /numpy/linalg/_linalg.py :461
Signature
def tensorinv ( a , ind = 2 ) Summary
Compute the 'inverse' of an N-dimensional array.
Extended Summary
The result is an inverse for a relative to the tensordot operation tensordot(a, b, ind), i. e., up to floating-point accuracy, tensordot(tensorinv(a), a, ind) is the "identity" tensor for the tensordot operation.
Parameters
a: array_likeTensor to 'invert'. Its shape must be 'square', i. e.,
prod(a.shape[:ind]) == prod(a.shape[ind:]).ind: int, optionalNumber of first indices that are involved in the inverse sum. Must be a positive integer, default is 2.
Returns
b: ndarraya's tensordot inverse, shapea.shape[ind:] + a.shape[:ind].
Raises
: LinAlgErrorIf
ais singular or not 'square' (in the above sense).
Examples
import numpy as np a = np.eye(4*6).reshape((4, 6, 8, 3)) ainv = np.linalg.tensorinv(a, ind=2) ainv.shape rng = np.random.default_rng() b = rng.normal(size=(4, 6)) np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b))✓
a = np.eye(4*6).reshape((24, 8, 3)) ainv = np.linalg.tensorinv(a, ind=1) ainv.shape rng = np.random.default_rng() b = rng.normal(size=24) np.allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b))✓
See also
- numpy.tensordot
- tensorsolve
Aliases
-
numpy.linalg.tensorinv