We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← JAX Numerical Computing step 8 of 25
Medium
Primitives
SVD Singular Values
Why this matters
The Singular Value Decomposition (SVD) factors A = U @ diag(s) @ V.T, where U and V have orthonormal columns and s contains the singular values (non-negative, sorted descending). The singular values reveal:
- Rank — count of nonzero singular values = rank(A).
- Condition number — s[0] / s[-1]; large values mean ill-conditioned.
- Low-rank approximation — keep only the top-k singular values for a rank-k approximation of A (Eckart–Young theorem).
Key applications:
- PCA — SVD of the centered data matrix X gives principal components.
- Latent semantic analysis — document-term matrix compression.
- Matrix completion / recommender systems — low-rank structure.
Worked mini-example
import jax.numpy as jnp
A = jnp.array([[3.0, 0.0],
[0.0, 4.0]])
s = jnp.linalg.svd(A, compute_uv=False)
# s = [4.0, 3.0] — sorted descending
Common pitfalls
- Output is sorted DESCENDING — s[0] is the largest singular value.
-
compute_uv=False— returns just the singular values (cheaper); omitting it returns(U, s, Vh)where Vh = V.T. - Count — for an (m, n) matrix, len(s) = min(m, n).
Problem
Implement svd_singular_values(A) that returns the singular values of A
as a 1-D array sorted in descending order.
-
A: 2-D jax array (m, n). - Returns: 1-D array (min(m, n),) — singular values, sorted descending.
Nothing accepted yet. When a submission passes, the code that passed shows up
here, one entry per mode.
Stuck?
JAX reference solution
Sign in to attempt this problem and reveal the reference solution.