Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
SciPy - Linear Algebra (scipy.linalg)
What is the output of the following code?
import numpy as np
from scipy.linalg import eig
A = np.array([[2, 0], [0, 3]])
values, vectors = eig(A)
print(values)
A[2.+0.j 3.+0.j]
B[0.+2.j 0.+3.j]
C[5.+0.j 0.+0.j]
D[2 3]
Step-by-Step Solution
Solution:
  1. Step 1: Understand matrix and eig function

    Matrix A is diagonal with values 2 and 3 on the diagonal. Eigenvalues of a diagonal matrix are the diagonal elements.
  2. Step 2: Predict output of eig

    scipy.linalg.eig returns eigenvalues as complex numbers, so output will be [2.+0.j 3.+0.j].
  3. Final Answer:

    [2.+0.j 3.+0.j] -> Option A
  4. Quick Check:

    Diagonal matrix eigenvalues = diagonal elements [OK]
Quick Trick: Diagonal matrix eigenvalues = diagonal entries as complex numbers [OK]
Common Mistakes:
MISTAKES
  • Expecting real numbers instead of complex
  • Adding eigenvalues instead of listing
  • Confusing eigenvalues with eigenvectors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes