numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturns
pinv(a, rcond=1e-15, hermitian=False)

Calculate the generalized inverse of a matrix using its singular-value decomposition (SVD) and including all large singular values.

versionchanged

Can now operate on stacks of matrices

Notes

The pseudo-inverse of a matrix A, denoted $A^+$ , is defined 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 singular value decomposition of A, then $A^+ = Q_2 \Sigma^+ Q_1^T$ , where $Q_{1,2}$ are orthogonal matrices, $\Sigma$ is a diagonal matrix consisting of A's so-called singular values, (followed, typically, by zeros), and then $\Sigma^+$ is simply the diagonal matrix consisting of the reciprocals of A's singular values (again, followed by zeros).

Parameters

a : (..., M, N) array_like

Matrix or stack of matrices to be pseudo-inverted.

rcond : (...) array_like of float

Cutoff for small singular values. Singular values less than or equal to rcond * largest_singular_value are set to zero. Broadcasts against the stack of matrices.

hermitian : bool, 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.

versionadded

Raises

LinAlgError

If the SVD computation does not converge.

Returns

B : (..., N, M) ndarray

The pseudo-inverse of a. If a is a matrix instance, then so is B.

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

See Also

scipy.linalg.pinv

Similar function in SciPy.

scipy.linalg.pinv2

Similar function in SciPy (SVD-based).

scipy.linalg.pinvh

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

Examples

The following example checks that a * a+ * a == a and a+ * a * a+ == a+ :

>>> a = np.random.randn(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
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/linalg/linalg.py#1903
type: <class 'function'>
Commit: