SciPy's sparse module is used for working with sparse matrices, which are memory-efficient for storing large matrices with many zero elements.
from scipy.sparse import csr_matrix # Creating a sparse matrix sparse_matrix = csr_matrix([[0, 0, 3], [4, 0, 0], [0, 2, 0]]) print("Sparse Matrix:\n", sparse_matrix) print("Dense Matrix:\n", sparse_matrix.toarray())
Here, we create a sparse matrix using the Compressed Sparse Row (CSR) format and then convert it to a dense matrix for display.