0
0
SciPydata~10 mins

Sparse matrix factorizations 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 matrix module from scipy.

SciPy
from scipy import [1]
Drag options to blanks, or click blank then click option'
Astats
Boptimize
Cintegrate
Dsparse
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong scipy submodule like optimize or stats.
Trying to import sparse as a function instead of a module.
2fill in blank
medium

Complete the code to create a CSR sparse matrix from data, rows, and columns arrays.

SciPy
from scipy.sparse import csr_matrix

matrix = csr_matrix((data, (rows, [1])))
Drag options to blanks, or click blank then click option'
Acols
Bvalues
Cindices
Dshape
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'values' instead of column indices.
Confusing 'indices' with 'cols'.
3fill in blank
hard

Fix the error in the code to perform LU factorization on a sparse matrix.

SciPy
from scipy.sparse.linalg import [1]

lu = [1](matrix)
Drag options to blanks, or click blank then click option'
Asplu
Bspsolve
Clu_factor
Dfactorize
Attempts:
3 left
💡 Hint
Common Mistakes
Using lu_factor which does not support sparse matrices.
Using spsolve which solves linear systems but does not factorize.
4fill in blank
hard

Fill both blanks to compute the LU factorization of a sparse matrix and solve a system.

SciPy
from scipy.sparse.linalg import [1]

lu = [1](matrix)
result = lu.[2](b)
Drag options to blanks, or click blank then click option'
Acholesky
Bsolve
Csplu
Dfactorize
Attempts:
3 left
💡 Hint
Common Mistakes
Using cholesky instead of splu for sparse factorization.
Calling a non-existent method instead of solve.
5fill in blank
hard

Fill all three blanks to create a sparse identity matrix, convert it to CSC format, and perform LU factorization.

SciPy
from scipy.sparse import identity
from scipy.sparse.linalg import [1]

I = identity(5).[2]()
lu = [3](I)
Drag options to blanks, or click blank then click option'
Asplu
Btocsc
Ccsr_matrix
Dcsc_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Using csr_matrix instead of converting to CSC.
Trying to factorize without converting to CSC format.