Complete the code to import the sparse linear solver from scipy.
from scipy.sparse.linalg import [1]
The function spsolve is the correct sparse linear algebra solver in scipy.
Complete the code to create a sparse matrix in CSR format.
from scipy.sparse import [1] matrix = [1]((data, (row_indices, col_indices)), shape=(4, 4))
The csr_matrix is the Compressed Sparse Row format, commonly used for efficient arithmetic and matrix vector operations.
Fix the error in solving a sparse linear system using spsolve.
from scipy.sparse.linalg import spsolve from scipy.sparse import csr_matrix A = csr_matrix([[3, 0], [0, 4]]) b = [6, 8] x = spsolve(A, [1])
The right-hand side vector b must be passed to spsolve to solve Ax = b.
Fill both blanks to create a sparse diagonal matrix and solve the system.
from scipy.sparse import [1] from scipy.sparse.linalg import [2] D = [1]([1, 2, 3, 4]) b = [1, 4, 9, 16] x = [2](D, b)
csr_matrix to create diagonal matrix without specifying diagonals.solve which is for dense matrices.diags creates a sparse diagonal matrix. spsolve solves the sparse linear system.
Fill all three blanks to create a sparse matrix, convert it to CSR format, and solve the system.
from scipy.sparse import [1] from scipy.sparse.linalg import [2] coo = [1]((data, (rows, cols)), shape=(3, 3)) csr = coo.[3]() b = [1, 2, 3] x = [2](csr, b)
csr_matrix constructor instead of conversion method.coo_matrix creates a sparse matrix in coordinate format. tocsr() converts it to CSR format. spsolve solves the system.