Bird
0
0

Given the following code, what will be the shape of the matrix U returned by svds?

medium📝 Predict Output Q13 of 15
SciPy - Sparse Linear Algebra
Given the following code, what will be the shape of the matrix U returned by svds?
import numpy as np
from scipy.sparse.linalg import svds
from scipy.sparse import csr_matrix

A = csr_matrix(np.array([[1, 0, 0], [0, 2, 0], [0, 0, 3]]))
U, S, Vt = svds(A, k=2)
A(3, 3)
B(3, 2)
C(2, 3)
D(2, 2)
Step-by-Step Solution
Solution:
  1. Step 1: Understand svds output shapes

    For an input matrix of shape (m, n) and parameter k, svds returns U with shape (m, k), S with length k, and Vt with shape (k, n).
  2. Step 2: Apply to given matrix

    Matrix A is 3x3, k=2, so U shape is (3, 2).
  3. Final Answer:

    (3, 2) -> Option B
  4. Quick Check:

    U shape = (rows, k) = (3, 2) [OK]
Quick Trick: U shape is (rows, k) where k is number of singular values [OK]
Common Mistakes:
  • Confusing U shape with Vt shape
  • Assuming U is square matrix
  • Mixing up k with matrix dimensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes