bundles / scipy latest / scipy / linalg / _basic / inv
function
scipy.linalg._basic:inv
source: /scipy/linalg/_basic.py :1353
Signature
def inv ( a , overwrite_a = False , check_finite = True , * , assume_a = None , lower = False ) Summary
Compute the inverse of a matrix.
Extended Summary
If the data matrix is known to be a particular type then supplying the corresponding string to assume_a key chooses the dedicated solver. The available options are
============================= ================================ general 'general' (or 'gen') diagonal 'diagonal' upper triangular 'upper triangular' lower triangular 'lower triangular' symmetric positive definite 'pos' symmetric 'sym' Hermitian 'her' ============================= ================================
For the 'pos' option, only the triangle of the input matrix specified in the lower argument is used, and the other triangle is not referenced. Likewise, an explicit assume_a='diagonal' means that off-diagonal elements are not referenced.
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 linalg_batch for details.
Parameters
a: array_like, shape (..., M, M)Square matrix (or a batch of matrices) to be inverted.
overwrite_a: bool, optionalDiscard data in
a(may improve performance). Default is False.check_finite: bool, optionalWhether 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.
assume_a: str, optionalValid entries are described above. If omitted or
None, checks are performed to identify structure so the appropriate solver can be called.lower: bool, optionalIgnored unless
assume_ais one of 'sym', 'her', or 'pos'. If True, the calculation uses only the data in the lower triangle ofa; entries above the diagonal are ignored. If False (default), the calculation uses only the data in the upper triangle ofa; entries below the diagonal are ignored.
Returns
ainv: ndarrayInverse of the matrix
a.
Raises
: LinAlgErrorIf
ais singular.: ValueErrorIf
ais not square, or not 2D.
Notes
The input array a may represent a single matrix or a collection (a.k.a. a "batch") of square matrices. For example, if a.shape == (4, 3, 2, 2), it is interpreted as a (4, 3)-shaped batch of matrices.
This routine checks the condition number of the a matrix and emits a LinAlgWarning for ill-conditioned inputs.
Examples
import numpy as np from scipy import linalg a = np.array([[1., 2.], [3., 4.]]) linalg.inv(a)✓
np.dot(a, linalg.inv(a))
✗Aliases
-
scipy.linalg.inv