Matrix reconstruction
Recover or verify a matrix factorization from singular vectors and values.
SciPy · Function
Computes the singular value decomposition of a matrix, returning singular values and optionally the corresponding unitary factors. It supports full or reduced factors and selectable LAPACK drivers.
The function decomposes a matrix into left singular vectors, nonnegative singular values, and the conjugate-transposed right singular-vector matrix. It can return only the values, use reduced or full unitary factors, validate finite entries, and select either of two LAPACK implementations.
scipy.linalg.svd(a, full_matrices=True, compute_uv=True, overwrite_a=False, check_finite=True, lapack_driver='gesdd')| Name | Type | Description |
|---|---|---|
a | array_like | Input matrix to decompose. |
full_matrices | bool, optional | If True, return full-sized unitary factors; otherwise return the reduced factors. |
compute_uv | bool, optional | If True, return U and Vh as well as s; otherwise return only s. |
overwrite_a | bool, optional | If True, allow overwriting the input array to improve performance. |
check_finite | bool, optional | If True, check that the input contains only finite values. |
lapack_driver | {'gesdd', 'gesvd'}, optional | LAPACK implementation: 'gesdd' or 'gesvd'. |
If compute_uv is True, returns U, s, and Vh. U contains left singular vectors, s contains the singular values, and Vh contains right singular vectors as rows; if compute_uv is False, returns only s.
import numpy as np
from scipy.linalg import svd
a = np.array([[1.0, 2.0], [3.0, 4.0]])
u, s, vh = svd(a, full_matrices=False)
reconstructed = u @ np.diag(s) @ vh
print(np.allclose(a, reconstructed))
print(s)Computes the reduced SVD and reconstructs the input from its factors.
Recover or verify a matrix factorization from singular vectors and values.
Keep only dominant singular components for a compact representation or denoising workflow.
Inspect numerical rank or conditioning through the ordered singular spectrum.
It returns U, s, and Vh such that the input equals U @ S @ Vh, where S places the one-dimensional singular-value array on its main diagonal. The singular values are real, nonnegative, and sorted from largest to smallest.
Follow-up: How would you obtain a reduced factorization? Pass full_matrices=False; then the factor dimensions use K = min(M, N) rather than padding to full square unitary matrices.
With full_matrices=True, U has shape (M, M) and Vh has shape (N, N). With full_matrices=False, their shapes become (M, K) and (K, N), where K is min(M, N).
Follow-up: Why prefer the reduced form for a large rectangular matrix? It avoids carrying dimensions that do not contribute to the K singular values, reducing storage and multiplication work.
compute_uv=False makes the function return only s, rather than U, s, and Vh. This is useful when only the singular spectrum is needed and avoids computing the singular vectors.
Follow-up: Which LAPACK driver can be selected? lapack_driver accepts gesdd or gesvd; gesdd uses divide-and-conquer, while gesvd uses the general rectangular approach.
scipy.linalg.diagsvdscipy.linalg.svdvalsscipy.linalg.eigscipy.linalg.eigh