bundles / numpy 2.4.4 / numpy / linalg / pinv
_ArrayFunctionDispatcher
numpy.linalg:pinv
source: /numpy/linalg/_linalg.py :2153
Signature
def pinv ( a , rcond = None , hermitian = False , * , rtol = <no value> ) Summary
Compute the (Moore-Penrose) pseudo-inverse of a matrix.
Extended Summary
Calculate the generalized inverse of a matrix using its singular-value decomposition (SVD) and including all large singular values.
Parameters
a: (..., M, N) array_likeMatrix or stack of matrices to be pseudo-inverted.
rcond: (...) array_like of float, optionalCutoff for small singular values. Singular values less than or equal to
rcond * largest_singular_valueare set to zero. Broadcasts against the stack of matrices. Default:1e-15.hermitian: bool, optionalIf True,
ais assumed to be Hermitian (symmetric if real-valued), enabling a more efficient method for finding singular values. Defaults to False.rtol: (...) array_like of float, optionalSame as
rcond, but it's an Array API compatible parameter name. Onlyrcondorrtolcan be set at a time. If none of them are provided then NumPy's1e-15default is used. Ifrtol=Noneis passed then the API standard default is used.
Returns
B: (..., N, M) ndarrayThe pseudo-inverse of
a. Ifais a matrix instance, then so is B.
Raises
: LinAlgErrorIf the SVD computation does not converge.
Notes
The pseudo-inverse of a matrix A, denoted , is defined as: "the matrix that 'solves' [the least-squares problem] ," i.e., if is said solution, then is that matrix such that .
It can be shown that if is the singular value decomposition of A, then , where are orthogonal matrices, is a diagonal matrix consisting of A's so-called singular values, (followed, typically, by zeros), and then is simply the diagonal matrix consisting of the reciprocals of A's singular values (again, followed by zeros). [1]
Examples
The following example checks that ``a * a+ * a == a`` and ``a+ * a * a+ == a+``:import numpy as np rng = np.random.default_rng() a = rng.normal(size=(9, 6)) B = np.linalg.pinv(a) np.allclose(a, np.dot(a, np.dot(B, a))) np.allclose(B, np.dot(B, np.dot(a, B)))✓
See also
- scipy.linalg.pinv
Similar function in SciPy.
- scipy.linalg.pinvh
Compute the (Moore-Penrose) pseudo-inverse of a Hermitian matrix.
Aliases
-
numpy.linalg.pinv