bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / linalg / inv
_ArrayFunctionDispatcher
numpy.linalg:inv
source: build-install/usr/lib/python3.14/site-packages/numpy/linalg/_linalg.py :536
Signature
def inv ( a ) Summary
Compute the inverse of a matrix.
Extended Summary
Given a square matrix a, return the matrix ainv satisfying a @ ainv = ainv @ a = eye(a.shape[0]).
Parameters
a: (..., M, M) array_likeMatrix to be inverted.
Returns
ainv: (..., M, M) ndarray or matrixInverse of the matrix
a.
Raises
: LinAlgErrorIf
ais not square or inversion fails.
Notes
Broadcasting rules apply, see the numpy.linalg documentation for details.
If a is detected to be singular, a LinAlgError is raised. If a is ill-conditioned, a LinAlgError may or may not be raised, and results may be inaccurate due to floating-point errors.
Examples
import numpy as np from numpy.linalg import inv a = np.array([[1., 2.], [3., 4.]]) ainv = inv(a) np.allclose(a @ ainv, np.eye(2)) np.allclose(ainv @ a, np.eye(2))✓
ainv = inv(np.matrix(a)) ainv✓
a = np.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]])
✓inv(a)
✗a = np.array([[2,4,6],[2,0,2],[6,8,14]])
✓inv(a) # No errors raised a @ inv(a)✗
from numpy.linalg import cond
✓cond(a)
✗from numpy.linalg import svd sigma = svd(a, compute_uv=False) # Do not compute singular vectors✓
sigma.max()/sigma.min()
✗See also
- numpy.linalg.cond
Compute the condition number of a matrix.
- numpy.linalg.svd
Compute the singular value decomposition of a matrix.
- scipy.linalg.inv
Similar function in SciPy.
Aliases
-
numpy.linalg.inv