Bird
0
0

Given the code below, what will be the output of print(vals)?

medium📝 Predict Output Q13 of 15
SciPy - Sparse Linear Algebra
Given the code below, what will be the output of print(vals)?
import numpy as np
from scipy.sparse.linalg import eigsh

A = np.array([[2, 1], [1, 2]])
vals, vecs = eigsh(A, k=1, which='LM')
print(np.round(vals, 2))
A[2.00]
B[1.00]
C[3.00]
D[0.00]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the matrix and eigenvalues

    Matrix A is symmetric with values [[2,1],[1,2]]. Its eigenvalues are 3 and 1.
  2. Step 2: Check the function call parameters

    eigsh is called with k=1 and which='LM' meaning largest magnitude eigenvalue. So it returns the largest eigenvalue, which is 3.
  3. Final Answer:

    [3.00] -> Option C
  4. Quick Check:

    Largest eigenvalue = 3.00 [OK]
Quick Trick: which='LM' returns largest eigenvalue [OK]
Common Mistakes:
  • Confusing largest eigenvalue with smallest
  • Not rounding output
  • Using eigs instead of eigsh for symmetric matrix

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes