Least-squares solutions
Solving underdetermined or overdetermined linear systems.
NumPy · Function
Computes the Moore–Penrose pseudo-inverse of a matrix or stack of matrices using singular-value decomposition. Small singular values are discarded according to a cutoff.
pinv uses singular-value decomposition to construct a generalized inverse, retaining singular values above a cutoff and setting smaller ones to zero. It accepts a single matrix or a stack, and returns an array whose final dimensions reverse the input matrix dimensions.
numpy.linalg.pinv(a, rcond=None, hermitian=False, *, rtol=<no value>)| Name | Type | Description |
|---|---|---|
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. Values less than or equal to rcond * largest_singular_value are set to zero; it broadcasts against matrix stacks. Default: 1e-15. |
hermitian | bool, optional | Assume a is Hermitian, or symmetric when real-valued, enabling a more efficient singular-value method. Defaults to False. |
rtol | array_like, optional | Alternative array-like cutoff parameter; the current stable page lists it in the signature as rtol=<no value>. |
B, an (..., N, M) ndarray containing the pseudo-inverse of a; a matrix input produces a matrix output.
pinv when an ordinary inverse is unavailable or when a generalized inverse is required.rcond may broadcast over matrix stacks, so compatible per-matrix cutoffs are supported.rcond uses a default cutoff of 1e-15.rcond can materially change the result.hermitian=True only when the input really has the required Hermitian or real-symmetric structure.import numpy as np
A = np.array([[1.0, 2.0], [2.0, 4.0]])
B = np.linalg.pinv(A)
print(B)
print(np.allclose(A @ B @ A, A))Computes a pseudo-inverse for a rank-deficient matrix and checks one Moore–Penrose identity.
Solving underdetermined or overdetermined linear systems.
Matrices that are singular or rank-deficient.
Batch numerical workflows.
numpy.linalg.pinv compute its result?It computes the Moore–Penrose pseudo-inverse using singular-value decomposition. Singular values at or below the cutoff are treated as zero, while the remaining singular values contribute to the generalized inverse.
Follow-up: How does the output shape relate to the input? For an input shaped (..., M, N), the result is shaped (..., N, M), preserving any leading stack dimensions.
rcond control?rcond is the threshold multiplier applied to the largest singular value. Singular values no greater than rcond times that largest value are zeroed; its default is 1e-15.
Follow-up: What happens for a stack? The cutoff can broadcast against the stack of matrices, allowing different thresholds where compatible.
hermitian=True appropriate?hermitian=True tells NumPy to assume the matrix is Hermitian, or symmetric for real input, and enables a more efficient singular-value calculation. The default is False.
Follow-up: When should it remain false? If the assumption is not valid, leave it false rather than requesting the specialized path.
numpy.linalg.svdnumpy.linalg.invnumpy.linalg.matrix_rank