### Navigation

- index
- modules |
- next |
- previous |
- NumPy v1.3 Manual (DRAFT) »
- NumPy Reference »
- Routines »
- Linear algebra (`numpy.linalg`) »

# numpy.linalg.tensorinv

`numpy.linalg.``tensorinv`(a, ind=2)

  Find the ‘inverse’ of a N-d array

  The result is an inverse corresponding to the operation tensordot(a, b, ind), ie.,

  > x == tensordot(tensordot(tensorinv(a), a, ind), x, ind)
  >   == tensordot(tensordot(a, tensorinv(a), ind), x, ind)

  for all x (up to floating-point accuracy).

  Parameters: | a : array_like Tensor to ‘invert’. Its shape must ‘square’, ie., prod(a.shape[:ind]) == prod(a.shape[ind:]) ind : integer > 0 How many of the first indices are involved in the inverse sum.
  Returns: | b : array, shape a.shape[:ind]+a.shape[ind:] Raises LinAlgError if a is singular or not square :

  Examples

      >>> a = np.eye(4*6)
      >>> a.shape = (4,6,8,3)
      >>> ainv = np.linalg.tensorinv(a, ind=2)
      >>> ainv.shape
      (8, 3, 4, 6)
      >>> b = np.random.randn(4,6)
      >>> np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b))
      True

      >>> a = np.eye(4*6)
      >>> a.shape = (24,8,3)
      >>> ainv = np.linalg.tensorinv(a, ind=1)
      >>> ainv.shape
      (8, 3, 24)
      >>> b = np.random.randn(24)
      >>> np.allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b))
      True

### Navigation

- index
- modules |
- next |
- previous |
- NumPy v1.3 Manual (DRAFT) »
- NumPy Reference »
- Routines »
- Linear algebra (`numpy.linalg`) »