Bird
0
0

What will be the shape of U, s, and VT after running the following code?

medium📝 Predict Output Q4 of 15
SciPy - Linear Algebra (scipy.linalg)
What will be the shape of U, s, and VT after running the following code?
import numpy as np
from scipy.linalg import svd
A = np.array([[1, 2], [3, 4], [5, 6]])
U, s, VT = svd(A, full_matrices=False)
print(U.shape, s.shape, VT.shape)
A(3, 2), (2,), (2, 2)
B(3, 3), (3,), (3, 2)
C(3, 2), (3,), (2, 2)
D(2, 2), (2,), (2, 3)
Step-by-Step Solution
Solution:
  1. Step 1: Understand input matrix shape

    Matrix A is 3 rows by 2 columns (3x2).
  2. Step 2: Apply svd with full_matrices=False

    U shape is (3, 2), s is length 2, VT is (2, 2).
  3. Final Answer:

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

    Shapes = (3,2), (2,), (2,2) [OK]
Quick Trick: full_matrices=False makes U shape (m, n) for m>n [OK]
Common Mistakes:
MISTAKES
  • Assuming full U shape (3,3)
  • Confusing s length with rows
  • Mixing VT shape with U shape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes