Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is an eigenvalue in the context of matrices?
An eigenvalue is a special number associated with a matrix that shows how a vector changes when the matrix is applied to it. Specifically, if you multiply the matrix by a vector and the result is the same vector scaled by this number, that number is the eigenvalue.
Click to reveal answer
beginner
What does the function scipy.sparse.linalg.eigs do?
The function eigs finds a few eigenvalues and eigenvectors of a square matrix, especially when the matrix is large and sparse. It works for general (not necessarily symmetric) matrices.
Click to reveal answer
intermediate
When should you use scipy.sparse.linalg.eigsh instead of eigs?
eigsh is designed for symmetric or Hermitian matrices. It is faster and more accurate for these types of matrices compared to eigs.
Click to reveal answer
beginner
What does the parameter k specify in eigs and eigsh?
The parameter k tells the function how many eigenvalues and eigenvectors to find. For example, k=3 means find 3 eigenvalues and their vectors.
Click to reveal answer
beginner
Why might you want to find only a few eigenvalues instead of all of them?
For very large matrices, finding all eigenvalues is slow and uses a lot of memory. Often, only the largest or smallest eigenvalues are important for understanding the system, so finding just a few saves time and resources.
Click to reveal answer
Which function is best for finding eigenvalues of a symmetric matrix?
Ascipy.sparse.linalg.eigs
Bscipy.sparse.linalg.eigsh
Cnumpy.linalg.eig
Dscipy.linalg.inv
✗ Incorrect
eigsh is optimized for symmetric or Hermitian matrices, making it the best choice here.
What does the k parameter control in eigs and eigsh?
ANumber of eigenvalues to find
BMatrix size
CTolerance level
DMaximum iterations
✗ Incorrect
k sets how many eigenvalues and eigenvectors the function returns.
If you have a large, non-symmetric matrix, which function should you use?
Ascipy.sparse.linalg.eigsh
Bnumpy.linalg.eigh
Cscipy.linalg.det
Dscipy.sparse.linalg.eigs
✗ Incorrect
eigs works for general matrices, including non-symmetric ones.
Why is it often unnecessary to compute all eigenvalues for large matrices?
ABecause only a few eigenvalues are usually important
BBecause eigenvalues are always the same
CBecause matrices have no eigenvalues
DBecause computing eigenvalues is always fast
✗ Incorrect
Usually, only the largest or smallest eigenvalues give useful information, so computing all is wasteful.
What type of matrix is required for eigsh to work correctly?
ANon-square
BDiagonal
CSymmetric or Hermitian
DSparse only
✗ Incorrect
eigsh requires the matrix to be symmetric or Hermitian for accurate results.
Explain the difference between eigs and eigsh in SciPy and when to use each.
Think about matrix symmetry and performance.
You got /4 concepts.
Describe why finding only a few eigenvalues is useful in data science or engineering problems.
Consider practical reasons and examples.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between scipy.sparse.linalg.eigs and scipy.sparse.linalg.eigsh?
easy
A. eigs returns eigenvectors only, while eigsh returns eigenvalues only.
B. eigs works for any square matrix, while eigsh is optimized for symmetric or Hermitian matrices.
C. eigsh works for any square matrix, while eigs only works for diagonal matrices.
D. eigsh is used for non-square matrices, while eigs is for square matrices.
Solution
Step 1: Understand the function purposes
eigs is designed to find eigenvalues and eigenvectors of any square matrix, including non-symmetric ones. eigsh is a specialized version optimized for symmetric or Hermitian matrices, which are common in many applications.
Step 2: Compare matrix types each function supports
eigsh takes advantage of symmetry to be faster and more accurate, but it requires the matrix to be symmetric. eigs has no such restriction but may be slower.
Final Answer:
eigs works for any square matrix, while eigsh is optimized for symmetric or Hermitian matrices. -> Option B
2. Which of the following is the correct way to import and use eigsh from scipy.sparse.linalg to compute 3 eigenvalues of a symmetric matrix A?
easy
A. from scipy.sparse.linalg import eigsh
vals, vecs = eigsh(A, k=3)
B. import scipy.linalg as la
vals, vecs = la.eigsh(A, 3)
C. from scipy.linalg import eigsh
vals, vecs = eigsh(A, 3)
D. from scipy.sparse.linalg import eigs
vals, vecs = eigs(A, k=3)
Solution
Step 1: Check the correct import statement
eigsh is in scipy.sparse.linalg, so the import must be from there, not scipy.linalg.
Step 2: Verify function call syntax
The function call requires the matrix A and the number of eigenvalues k=3. from scipy.sparse.linalg import eigsh
vals, vecs = eigsh(A, k=3) uses correct syntax and import.
Final Answer:
from scipy.sparse.linalg import eigsh
vals, vecs = eigsh(A, k=3) -> Option A
Quick Check:
Correct import and call = D [OK]
Hint: Import eigsh from scipy.sparse.linalg and use k=number [OK]
Common Mistakes:
Importing eigsh from scipy.linalg instead of scipy.sparse.linalg
Using eigs instead of eigsh for symmetric matrices
Passing number without keyword k
3. 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))
medium
A. [2.00]
B. [1.00]
C. [3.00]
D. [0.00]
Solution
Step 1: Understand the matrix and eigenvalues
Matrix A is symmetric with values [[2,1],[1,2]]. Its eigenvalues are 3 and 1.
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.
Final Answer:
[3.00] -> Option C
Quick Check:
Largest eigenvalue = 3.00 [OK]
Hint: which='LM' returns largest eigenvalue [OK]
Common Mistakes:
Confusing largest eigenvalue with smallest
Not rounding output
Using eigs instead of eigsh for symmetric matrix
4. The following code raises an error. What is the most likely cause?
import numpy as np
from scipy.sparse.linalg import eigsh
A = np.array([[1, 2], [3, 4]])
vals, vecs = eigsh(A, k=1)
medium
A. The import statement is incorrect.
B. The value of k is too large for the matrix size.
C. eigsh requires the matrix to be sparse, but A is dense.
D. Matrix A is not symmetric, so eigsh cannot be used.
Solution
Step 1: Check matrix properties
Matrix A = [[1,2],[3,4]] is not symmetric because A[0,1] != A[1,0].
Step 2: Understand eigsh requirements
eigsh requires the matrix to be symmetric or Hermitian. Using it on a non-symmetric matrix causes an error.
Final Answer:
Matrix A is not symmetric, so eigsh cannot be used. -> Option D
Quick Check:
Symmetry required for eigsh = A [OK]
Hint: Check matrix symmetry before using eigsh [OK]
Common Mistakes:
Assuming eigsh works on any matrix
Thinking k=1 is too large for 2x2 matrix
Believing eigsh only works on sparse matrices
5. You have a large symmetric matrix representing connections in a social network. You want to find the 5 smallest eigenvalues to analyze community structure. Which approach is best?
hard
A. Use eigsh with k=5 and which='SM' to get the smallest eigenvalues efficiently.
B. Use eigs with k=5 and which='LM' to get the largest eigenvalues.
C. Convert the matrix to dense and use numpy.linalg.eig to get all eigenvalues.
D. Use eigsh with k=5 and which='LM' to get the largest eigenvalues.
Solution
Step 1: Identify matrix type and goal
The matrix is large and symmetric, and we want the 5 smallest eigenvalues to study community structure.
Step 2: Choose appropriate function and parameters
eigsh is optimized for symmetric matrices. Using k=5 and which='SM' returns the smallest magnitude eigenvalues efficiently without computing all eigenvalues.
Step 3: Evaluate other options
eigs is less efficient for symmetric matrices. Converting to dense is costly for large matrices. Getting largest eigenvalues is not the goal.
Final Answer:
Use eigsh with k=5 and which='SM' to get the smallest eigenvalues efficiently. -> Option A