Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
SciPy - Linear Algebra (scipy.linalg)
Identify the error in the following code snippet:
from scipy.linalg import svd
A = [[1, 2], 3]
U, s, VT = svd(A)
print(U)
AA should be a numpy array, not a list
Bsvd function is not imported correctly
CU, s, VT should be unpacked as a single variable
Dprint(U) is invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Check input type for svd

    svd requires a numpy array, but A is a Python list.
  2. Step 2: Identify fix

    Convert A to numpy array using np.array(A) before svd call.
  3. Final Answer:

    A should be a numpy array, not a list -> Option A
  4. Quick Check:

    Input type error = list instead of array [OK]
Quick Trick: Always convert input to numpy array before svd [OK]
Common Mistakes:
MISTAKES
  • Passing list directly
  • Wrong import statement
  • Misusing print function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes