Complete the code to import the CSC matrix class from scipy.
from scipy.sparse import [1]
The csc_matrix class is used to create and work with Compressed Sparse Column matrices in scipy.
Complete the code to create a 3x3 CSC matrix with data [1, 2, 3] at positions (0,0), (1,1), and (2,2).
from scipy.sparse import csc_matrix import numpy as np row = np.array([0, 1, 2]) col = np.array([0, 1, 2]) data = np.array([1, 2, 3]) matrix = csc_matrix(([1], (row, col)), shape=(3, 3))
The first argument to csc_matrix is the data array containing the nonzero values.
Fix the error in the code to convert a dense numpy array to a CSC matrix.
import numpy as np from scipy.sparse import csc_matrix dense = np.array([[0, 1], [2, 0]]) sparse = [1](dense)
To convert a dense array to a CSC matrix, use csc_matrix constructor.
Fill both blanks to create a CSC matrix and then get its shape.
from scipy.sparse import [1] import numpy as np data = np.array([4, 5, 6]) row = np.array([0, 1, 2]) col = np.array([0, 1, 2]) matrix = [2]((data, (row, col)), shape=(3, 3)) shape = matrix.shape
Both blanks require csc_matrix to create the matrix and import the class.
Fill all three blanks to create a CSC matrix, convert it to dense, and print the result.
from scipy.sparse import [1] data = [7, 8, 9] row = [0, 1, 2] col = [0, 1, 2] matrix = [2]((data, (row, col)), shape=(3, 3)) dense_matrix = matrix.[3]() print(dense_matrix)
toarray() instead of todense()Import and create the CSC matrix with csc_matrix. To convert to dense, use todense() method.