Bird
0
0

What will be the output of print(np.round(vals, 3)) in the following code?

medium📝 Predict Output Q5 of 15
SciPy - Sparse Linear Algebra
What will be the output of print(np.round(vals, 3)) in the following code?
import numpy as np
from scipy.sparse.linalg import eigsh

M = np.array([[4, 1], [1, 3]])
vals, vecs = eigsh(M, k=2, which='LA')
print(np.round(vals, 3))
A[4.000 3.000]
B[5.000 2.000]
C[3.000 4.000]
D[4.618 2.382]
Step-by-Step Solution
Solution:
  1. Step 1: Understand matrix and parameters

    Matrix M is symmetric. which='LA' returns largest algebraic eigenvalues.
  2. Step 2: Calculate eigenvalues

    Eigenvalues of M are approximately 4.618 and 2.382.
  3. Final Answer:

    [4.618 2.382] -> Option D
  4. Quick Check:

    Check eigenvalues with np.linalg.eigvals [OK]
Quick Trick: which='LA' returns largest eigenvalues [OK]
Common Mistakes:
  • Confusing which='LA' with smallest eigenvalues
  • Rounding incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes