Recall & Review
beginner
What is the purpose of converting between formats in SciPy?
Converting between formats in SciPy helps to change data from one type or structure to another, making it easier to use different functions or save data in a preferred way.
Click to reveal answer
beginner
How do you convert a dense matrix to a sparse matrix in SciPy?
You can convert a dense matrix (like a NumPy array) to a sparse matrix using SciPy's sparse module, for example: <br><code>from scipy import sparse<br>import numpy as np<br>dense = np.array([[1, 0], [0, 2]])<br>sparse_matrix = sparse.csr_matrix(dense)</code>Click to reveal answer
intermediate
What is the difference between CSR and COO sparse matrix formats?
CSR (Compressed Sparse Row) format stores matrix data by rows and is efficient for row slicing and matrix-vector products. COO (Coordinate) format stores data as (row, column, value) tuples and is easier for constructing sparse matrices but less efficient for arithmetic.
Click to reveal answer
beginner
How can you convert a sparse matrix back to a dense NumPy array?
Use the
.toarray() method on a sparse matrix to get a dense NumPy array. For example: <br>dense = sparse_matrix.toarray()Click to reveal answer
beginner
Why might you want to convert data to a sparse format?
Sparse formats save memory and speed up calculations when data has many zeros. This is common in large datasets like text data or graphs.
Click to reveal answer
Which SciPy function converts a dense matrix to CSR format?
✗ Incorrect
The function sparse.csr_matrix() converts dense matrices to CSR sparse format.
What method converts a sparse matrix back to a dense array?
✗ Incorrect
The toarray() method converts a sparse matrix to a dense NumPy array.
Which sparse format is best for fast row slicing?
✗ Incorrect
CSR (Compressed Sparse Row) format is optimized for fast row slicing.
Why use sparse matrices instead of dense ones?
✗ Incorrect
Sparse matrices save memory and speed up calculations when data has many zeros.
Which SciPy module contains functions for sparse matrices?
✗ Incorrect
The scipy.sparse module contains sparse matrix functions.
Explain how to convert a dense NumPy array to a sparse matrix and why you might do this.
Think about saving memory and speeding up calculations.
You got /4 concepts.
Describe the difference between CSR and COO sparse matrix formats and when to use each.
Consider how data is stored and what operations are faster.
You got /4 concepts.