numpy.linalg.tensorsolve

numpy.linalg.tensorsolve(a, b, axes=None)

Solve the tensor equation a x = b for x

It is assumed that all indices of x are summed over in the product, together with the rightmost indices of a, similarly as in tensordot(a, x, axes=len(b.shape)).

Parameters:

a : array_like, shape b.shape+Q

Coefficient tensor. Shape Q of the rightmost indices of a must be such that a is ‘square’, ie., prod(Q) == prod(b.shape).

b : array_like, any shape

Right-hand tensor.

axes : tuple of integers

Axes in a to reorder to the right, before inversion. If None (default), no reordering is done.

Returns:

x : array, shape Q

Examples

>>> a = np.eye(2*3*4)
>>> a.shape = (2*3,4,  2,3,4)
>>> b = np.random.randn(2*3,4)
>>> x = np.linalg.tensorsolve(a, b)
>>> x.shape
(2, 3, 4)
>>> np.allclose(np.tensordot(a, x, axes=3), b)
True

Previous topic

numpy.linalg.solve

Next topic

numpy.linalg.lstsq

This Page

Quick search