Recall & Review
beginner
What is a sparse matrix?
A sparse matrix is a matrix mostly filled with zeros. It saves memory by only storing the non-zero values and their positions.
Click to reveal answer
beginner
Name two common formats for sparse matrices in SciPy.
Two common formats are CSR (Compressed Sparse Row) and COO (Coordinate list). CSR is good for fast row slicing, COO is easy to create.
Click to reveal answer
beginner
How do you create a COO sparse matrix in SciPy?
Use scipy.sparse.coo_matrix with three arrays: data (values), row indices, and column indices.
Click to reveal answer
beginner
Why use sparse matrices instead of regular dense matrices?
Sparse matrices save memory and speed up calculations when most values are zero, like in large graphs or text data.
Click to reveal answer
intermediate
What function creates a CSR sparse matrix from dense data?
Use scipy.sparse.csr_matrix with a dense matrix or arrays. It converts dense data into compressed sparse row format.
Click to reveal answer
Which SciPy function creates a sparse matrix from data, row, and column arrays?
✗ Incorrect
The coo_matrix function creates a sparse matrix using data, row, and column arrays.
What is the main benefit of using sparse matrices?
✗ Incorrect
Sparse matrices save memory by storing only non-zero values.
Which sparse matrix format is best for fast row slicing?
✗ Incorrect
CSR (Compressed Sparse Row) format is optimized for fast row slicing.
How do you convert a dense matrix to a CSR sparse matrix?
✗ Incorrect
csr_matrix can take a dense matrix and convert it to CSR format.
Which of these is NOT a sparse matrix format in SciPy?
✗ Incorrect
XYZ is not a recognized sparse matrix format in SciPy.
Explain how to create a sparse matrix using the COO format in SciPy.
Think about what information you need to specify the non-zero values and their positions.
You got /4 concepts.
Describe why sparse matrices are useful and when you would use them.
Consider situations with many zeros in data.
You got /4 concepts.