Complete the code to import the sparse SVD function from scipy.
from scipy.sparse.linalg import [1]
The function svds is the correct sparse SVD function in scipy.sparse.linalg.
Complete the code to create a sparse matrix using scipy.
from scipy.sparse import [1] data = [1]((3, 3))
csr_matrix creates a compressed sparse row matrix, commonly used for sparse data.
Fix the error in the code to compute the top 2 singular values and vectors of a sparse matrix.
u, s, vt = svds(data, k=[1])The parameter k specifies the number of singular values and vectors to compute. For top 2, use k=2.
Fill both blanks to create a sparse matrix and compute its sparse SVD with 1 singular value.
from scipy.sparse import [1] from scipy.sparse.linalg import svds matrix = [1]([[1, 0], [0, 1]]) u, s, vt = svds(matrix, k=[2])
Use csr_matrix to create the sparse matrix and k=1 to compute one singular value.
Fill all three blanks to compute sparse SVD and reconstruct the original matrix.
u, s, vt = svds(matrix, k=[1]) S = np.diag(s) reconstructed = u [2] S [3] vt
Use k=1 for one singular value. Matrix multiplication is done with the @ operator in Python for arrays.