0
0
SciPydata~10 mins

Eigenvalue problems (eigs, eigsh) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function for computing eigenvalues of a sparse matrix.

SciPy
from scipy.sparse.linalg import [1]
Drag options to blanks, or click blank then click option'
Asvd
Beigs
Ceig
Deigsh
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing eigs with eigsh which is for symmetric matrices.
Trying to import eig from scipy.linalg instead of scipy.sparse.linalg.
2fill in blank
medium

Complete the code to compute the 3 largest magnitude eigenvalues of a sparse matrix A using eigs.

SciPy
vals, vecs = eigs(A, k=[1])
Drag options to blanks, or click blank then click option'
A10
B5
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value of k larger than the matrix size.
Confusing k with the index of eigenvalues.
3fill in blank
hard

Fix the error in the code to compute the 2 smallest eigenvalues of a symmetric matrix using eigsh.

SciPy
vals, vecs = eigsh(A, k=[1], which='SM')
Drag options to blanks, or click blank then click option'
A2
B1
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Setting k larger than matrix size.
Confusing eigsh with eigs.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

SciPy
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Checking if the word is greater than 3 instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if the value is positive.

SciPy
result = { [1]: [2] for [3], v in data.items() if v > 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dv.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the value instead of the key for uppercase conversion.
Using v as the key variable in the loop.