bundles / numpy 2.4.3 / numpy / linalg / tensorsolve
_ArrayFunctionDispatcher
numpy.linalg:tensorsolve
source: /numpy/linalg/_linalg.py :281
Signature
def tensorsolve ( a , b , axes = None ) Summary
Solve the tensor equation a x = b for x.
Extended Summary
It is assumed that all indices of x are summed over in the product, together with the rightmost indices of a, as is done in, for example, tensordot(a, x, axes=x.ndim).
Parameters
a: array_likeCoefficient tensor, of shape
b.shape + Q.Q, a tuple, equals the shape of that sub-tensor ofaconsisting of the appropriate number of its rightmost indices, and must be such thatprod(Q) == prod(b.shape)(in which senseais said to be 'square').b: array_likeRight-hand tensor, which can be of any shape.
axes: tuple of ints, optionalAxes in
ato reorder to the right, before inversion. If None (default), no reordering is done.
Returns
x: ndarray, shape Q
Raises
: LinAlgErrorIf
ais singular or not 'square' (in the above sense).
Examples
import numpy as np a = np.eye(2*3*4).reshape((2*3, 4, 2, 3, 4)) rng = np.random.default_rng() b = rng.normal(size=(2*3, 4)) x = np.linalg.tensorsolve(a, b) x.shape np.allclose(np.tensordot(a, x, axes=3), b)✓
See also
- numpy.einsum
- numpy.tensordot
- tensorinv
Aliases
-
numpy.linalg.tensorsolve