numpy.linalg.pinv#

linalg.pinv(a,rcond=None,hermitian=False,*,rtol=<novalue>)[source]#

Compute the (Moore-Penrose) pseudo-inverse of a matrix.

Calculate the generalized inverse of a matrix using itssingular-value decomposition (SVD) and including alllarge singular values.

Parameters:
a(…, M, N) array_like

Matrix or stack of matrices to be pseudo-inverted.

rcond(…) array_like of float, optional

Cutoff for small singular values.Singular values less than or equal torcond*largest_singular_value are set to zero.Broadcasts against the stack of matrices. Default:1e-15.

hermitianbool, optional

If True,a is 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, optional

Same asrcond, but it’s an Array API compatible parameter name.Onlyrcond orrtol can be set at a time. If none of them areprovided then NumPy’s1e-15 default is used. Ifrtol=Noneis passed then the API standard default is used.

New in version 2.0.0.

Returns:
B(…, N, M) ndarray

The pseudo-inverse ofa. Ifa is amatrix instance, then soisB.

Raises:
LinAlgError

If the SVD computation does not converge.

See also

scipy.linalg.pinv

Similar function in SciPy.

scipy.linalg.pinvh

Compute the (Moore-Penrose) pseudo-inverse of a Hermitian matrix.

Notes

The pseudo-inverse of a matrix A, denoted\(A^+\), isdefined as: “the matrix that ‘solves’ [the least-squares problem]\(Ax = b\),” i.e., if\(\bar{x}\) is said solution, then\(A^+\) is that matrix such that\(\bar{x} = A^+b\).

It can be shown that if\(Q_1 \Sigma Q_2^T = A\) is the singularvalue decomposition of A, then\(A^+ = Q_2 \Sigma^+ Q_1^T\), where\(Q_{1,2}\) areorthogonal matrices,\(\Sigma\) is a diagonal matrix consistingof A’s so-called singular values, (followed, typically, byzeros), and then\(\Sigma^+\) is simply the diagonal matrixconsisting of the reciprocals of A’s singular values(again, followed by zeros).[1]

References

[1]

G. Strang,Linear Algebra and Its Applications, 2nd Ed., Orlando,FL, Academic Press, Inc., 1980, pp. 139-142.

Examples

The following example checks thata*a+*a==a anda+*a*a+==a+:

>>>importnumpyasnp>>>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)))True>>>np.allclose(B,np.dot(B,np.dot(a,B)))True
On this page