Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
SciPy - Linear Algebra (scipy.linalg)
What is wrong with this code snippet?
import numpy as np
from scipy.linalg import eig
A = np.array([[0, 1], [-2, -3]])
vals, vecs = eig(A)
print(vecs[0])
AMatrix A is not square
Beig does not return eigenvectors
Cvecs[0] returns the first row, but eigenvectors are columns
Deig requires real matrices only
Step-by-Step Solution
Solution:
  1. Step 1: Understand eigenvectors matrix format

    Eigenvectors are columns of the returned matrix, not rows.
  2. Step 2: Identify indexing mistake

    Accessing vecs[0] returns the first row, not the first eigenvector.
  3. Final Answer:

    vecs[0] returns the first row, but eigenvectors are columns -> Option C
  4. Quick Check:

    Eigenvectors are columns in vecs matrix [OK]
Quick Trick: Eigenvectors are columns; index columns, not rows [OK]
Common Mistakes:
MISTAKES
  • Accessing eigenvectors by row index
  • Thinking eig returns only eigenvalues
  • Assuming matrix must be real

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes