Complete the code to import the function for computing eigenvalues of a sparse matrix.
from scipy.sparse.linalg import [1]
The eigs function computes eigenvalues and eigenvectors of a square matrix, suitable for sparse matrices.
Complete the code to compute the 3 largest magnitude eigenvalues of a sparse matrix A using eigs.
vals, vecs = eigs(A, k=[1])The parameter k specifies how many eigenvalues to compute. Here, we want 3.
Fix the error in the code to compute the 2 smallest eigenvalues of a symmetric matrix using eigsh.
vals, vecs = eigsh(A, k=[1], which='SM')
The parameter k should be 2 to compute 2 eigenvalues. Use which='SM' for the smallest magnitude eigenvalues.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
{word: [1] for word in words if [2]The dictionary maps each word to its length, so the value is len(word). The condition filters words with length greater than 3, so the condition is len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if the value is positive.
result = { [1]: [2] for [3], v in data.items() if v > 0 }The key is converted to uppercase with k.upper(). The value is v. The loop variable for keys is k.