mindspore.scipy.linalg.inv

mindspore.scipy.linalg.inv(a, overwrite_a=False, check_finite=True)[source]

Compute the inverse of a matrix.

Parameters
  • a (Tensor) – Square matrix to be inverted. Note that if the input tensor is not a float, then it will be casted to mstype.float32.

  • overwrite_a (bool, optional) – Discard data in a (may improve performance). Default: False.

  • check_finite (bool, optional) – Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Default: True.

Returns

Tensor, inverse of the matrix a.

Raises
  • LinAlgError – If \(a\) is singular.

  • ValueError – If \(a\) is not square, or not 2D.

Supported Platforms:

CPU GPU

Examples

>>> import numpy as onp
>>> from mindspore.common import Tensor
>>> import mindspore.numpy as mnp
>>> from mindspore.scipy.linalg import inv
>>> a = Tensor(onp.array([[1., 2.], [3., 4.]]))
>>> inv(a)
Tensor(shape=[2, 2], dtype=Float64, value=
[[-2.00000000e+00,  1.00000000e+00],
 [ 1.50000000e+00, -5.00000000e-01]])
>>> mnp.dot(a, inv(a))
Tensor(shape=[2, 2], dtype=Float64, value=
[[ 1.00000000e+00,  0.00000000e+00],
 [ 8.88178420e-16,  1.00000000e+00]])