0
0
SciPydata~10 mins

Why sparse solvers handle large systems in SciPy - Test Your Understanding

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

Complete the code to import the sparse linear solver from SciPy.

SciPy
from scipy.sparse.linalg import [1]
Drag options to blanks, or click blank then click option'
Asolve
Bspsolve
Clinalg
Dsparse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'solve' which is for dense matrices.
Importing 'linalg' instead of the solver function.
2fill in blank
medium

Complete the code to create a sparse matrix in CSR format.

SciPy
from scipy.sparse import [1]

matrix = [1]((data, (row, col)), shape=(4, 4))
Drag options to blanks, or click blank then click option'
Acsr_matrix
Bdense_matrix
Ccoo_matrix
Dcsc_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dense_matrix' which is not a sparse format.
Confusing CSR with COO format.
3fill in blank
hard

Fix the error in the code to solve a sparse linear system.

SciPy
from scipy.sparse.linalg import spsolve
from scipy.sparse import csr_matrix

A = csr_matrix([[3, 0], [0, 4]])
b = [6, 8]
x = spsolve([1], b)
Drag options to blanks, or click blank then click option'
Aspsolve
Bb
Ccsr_matrix
DA
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the vector 'b' as the first argument.
Passing the function name instead of the matrix.
4fill in blank
hard

Fill both blanks to create a sparse diagonal matrix and solve it.

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

D = [2]([1, 2, 3], 0, shape=(3, 3))
b = [1, 4, 9]
x = spsolve(D, b)
Drag options to blanks, or click blank then click option'
Adiags
Bcsr_matrix
Dcsc_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'csr_matrix' to create diagonal matrices directly.
Confusing 'diags' with 'csc_matrix'.
5fill in blank
hard

Fill all three blanks to create a sparse system and solve it efficiently.

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

A = [1]([[10, 0], [0, 5]])
b = [20, 15]
x = [2](A, b)
Drag options to blanks, or click blank then click option'
Acsr_matrix
Bspsolve
Dcsc_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Using dense matrix formats.
Mixing up the order of arguments.