Challenge - 5 Problems
Eigenvalue Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of scipy.sparse.linalg.eigs on a symmetric matrix
What is the output of the following code snippet? It computes eigenvalues and eigenvectors of a symmetric matrix using
eigs.SciPy
import numpy as np from scipy.sparse.linalg import eigs A = np.array([[2, 1], [1, 2]]) vals, vecs = eigs(A, k=1, which='LM') print(np.round(vals.real, 3))
Attempts:
2 left
💡 Hint
The matrix is symmetric with eigenvalues 3 and 1. 'which=LM' returns the largest magnitude eigenvalue.
✗ Incorrect
The matrix [[2,1],[1,2]] has eigenvalues 3 and 1. Using eigs with k=1 and which='LM' returns the largest eigenvalue, which is 3.
❓ data_output
intermediate1:30remaining
Number of eigenvalues returned by eigsh
Given a 5x5 sparse symmetric matrix, how many eigenvalues and eigenvectors will
eigsh return when called with k=3?SciPy
import numpy as np from scipy.sparse.linalg import eigsh A = np.diag(np.arange(1,6)) vals, vecs = eigsh(A, k=3) print(len(vals), vecs.shape)
Attempts:
2 left
💡 Hint
The parameter k controls how many eigenvalues and eigenvectors are returned.
✗ Incorrect
eigsh returns k eigenvalues and eigenvectors. For a 5x5 matrix with k=3, vals has length 3 and vecs shape is (5,3).
🔧 Debug
advanced1:30remaining
Error raised by eigs with k too large
What error does the following code raise? It tries to compute 5 eigenvalues of a 4x4 matrix using
eigs.SciPy
import numpy as np from scipy.sparse.linalg import eigs A = np.eye(4) vals, vecs = eigs(A, k=5)
Attempts:
2 left
💡 Hint
k must be less than the size of the matrix.
✗ Incorrect
eigs requires k < N where N is matrix size. Here k=5 and N=4, so ValueError is raised.
🧠 Conceptual
advanced2:00remaining
Difference between eigs and eigsh
Which statement correctly describes the difference between
eigs and eigsh in scipy?Attempts:
2 left
💡 Hint
Think about matrix symmetry and algorithm optimization.
✗ Incorrect
eigsh is optimized for symmetric or Hermitian matrices and is faster and more accurate for them. eigs works for any square matrix.🚀 Application
expert2:30remaining
Identifying dominant eigenvalue with eigs
You have a large sparse matrix representing a network. You want to find the dominant eigenvalue (largest magnitude) and its eigenvector using
eigs. Which code snippet correctly achieves this?Attempts:
2 left
💡 Hint
'LM' means largest magnitude eigenvalue.
✗ Incorrect
'LM' option in eigs returns eigenvalues with largest magnitude, which is the dominant eigenvalue.