Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

linalg.svd

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.

How it works

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.

Syntax

scipy.linalg.svd(a, full_matrices=True, compute_uv=True, overwrite_a=False, check_finite=True, lapack_driver='gesdd')

Parameters

NameTypeDescription
aarray_likeInput matrix to decompose.
full_matricesbool, optionalIf True, return full-sized unitary factors; otherwise return the reduced factors.
compute_uvbool, optionalIf True, return U and Vh as well as s; otherwise return only s.
overwrite_abool, optionalIf True, allow overwriting the input array to improve performance.
check_finitebool, optionalIf True, check that the input contains only finite values.
lapack_driver{'gesdd', 'gesvd'}, optionalLAPACK implementation: 'gesdd' or 'gesvd'.

Returns

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.

Key points

  • The decomposition produces U, s, and Vh, with U and Vh unitary and s containing the singular values.
  • Reconstruction uses a suitably shaped diagonal matrix S whose main diagonal is s.
  • The returned singular values are ordered from largest to smallest.
  • Set compute_uv=False when only the singular values are required.
  • For an M-by-N input, s always has K entries, where K is the smaller dimension.
  • lapack_driver chooses between the divide-and-conquer gesdd implementation and the general rectangular gesvd implementation.

Example: Reduced SVD and reconstruction

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.

When to use it

Matrix reconstruction

Recover or verify a matrix factorization from singular vectors and values.

Low-rank approximation

Keep only dominant singular components for a compact representation or denoising workflow.

Rank and conditioning analysis

Inspect numerical rank or conditioning through the ordered singular spectrum.

Interview questions

QWhat does scipy.linalg.svd return?

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.

QHow does full_matrices affect output shapes?

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.

QHow can you compute only singular values?

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.diagsvd
  • scipy.linalg.svdvals
  • scipy.linalg.eig
  • scipy.linalg.eigh

Source: svd. Checked 2026-10-15.