0
0
SciPydata~10 mins

Sparse SVD (svds) 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 sparse SVD function from scipy.

SciPy
from scipy.sparse.linalg import [1]
Drag options to blanks, or click blank then click option'
Asparse_svd_solver
Bsvd
Csparse_svd
Dsvds
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'svd' which is for dense matrices.
Trying to import a non-existent function like 'sparse_svd'.
2fill in blank
medium

Complete the code to create a sparse matrix using scipy.

SciPy
from scipy.sparse import [1]
data = [1]((3, 3))
Drag options to blanks, or click blank then click option'
Acoo_matrix
Bcsr_matrix
Ccsc_matrix
Ddense_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dense_matrix' which does not exist in scipy.sparse.
Choosing 'csc_matrix' which is column-based, not row-based.
3fill in blank
hard

Fix the error in the code to compute the top 2 singular values and vectors of a sparse matrix.

SciPy
u, s, vt = svds(data, k=[1])
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using k=3 when the matrix dimension is smaller.
Using k=0 which is invalid.
4fill in blank
hard

Fill both blanks to create a sparse matrix and compute its sparse SVD with 1 singular value.

SciPy
from scipy.sparse import [1]
from scipy.sparse.linalg import svds
matrix = [1]([[1, 0], [0, 1]])
u, s, vt = svds(matrix, k=[2])
Drag options to blanks, or click blank then click option'
Acsr_matrix
Bcsc_matrix
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'csc_matrix' instead of 'csr_matrix'.
Setting k to 2 when only 1 singular value is needed.
5fill in blank
hard

Fill all three blanks to compute sparse SVD and reconstruct the original matrix.

SciPy
u, s, vt = svds(matrix, k=[1])
S = np.diag(s)
reconstructed = u [2] S [3] vt
Drag options to blanks, or click blank then click option'
A2
B@
C*
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which does element-wise multiplication, not matrix multiplication.
Setting k to 2 when only 1 singular value is needed.