scipy.linalg.
inv#
- scipy.linalg.inv(a, overwrite_a=False, check_finite=True)[source]#
Compute the inverse of a matrix.
The documentation is written assuming array arguments are of specified “core” shapes. However, array argument(s) of this function may have additional “batch” dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see Batched Linear Operations for details.
- Parameters:
- aarray_like
Square matrix to be inverted.
- overwrite_abool, optional
Discard data in a (may improve performance). Default is False.
- check_finitebool, 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.
- Returns:
- ainvndarray
Inverse of the matrix a.
- Raises:
- LinAlgError
If a is singular.
- ValueError
If a is not square, or not 2D.
Examples
>>> import numpy as np >>> from scipy import linalg >>> a = np.array([[1., 2.], [3., 4.]]) >>> linalg.inv(a) array([[-2. , 1. ], [ 1.5, -0.5]]) >>> np.dot(a, linalg.inv(a)) array([[ 1., 0.], [ 0., 1.]])