CSC stands for Compressed Sparse Column. It is a way to store sparse matrices efficiently by compressing data column-wise.
Click to reveal answer
intermediate
How does CSC format store the matrix data?
CSC stores three arrays: one for non-zero values, one for row indices of those values, and one for column pointers that mark where each column starts in the values array.
Click to reveal answer
beginner
Why is CSC format useful in data science?
CSC format saves memory and speeds up column-based operations like matrix-vector multiplication, which is common in data science tasks.
Click to reveal answer
beginner
Show a simple example of creating a CSC matrix using scipy.
You can create a CSC matrix with scipy.sparse.csc_matrix. For example:<br><pre>from scipy.sparse import csc_matrix
import numpy as np
# Create a dense matrix
dense = np.array([[0, 0, 1], [1, 0, 0], [0, 2, 0]])
# Convert to CSC format
csc = csc_matrix(dense)
print(csc)</pre>
Click to reveal answer
intermediate
What is the difference between CSC and CSR formats?
CSC compresses columns and is efficient for column slicing and operations. CSR (Compressed Sparse Row) compresses rows and is better for row slicing and row-based operations.
Click to reveal answer
What does the 'indptr' array in CSC format represent?
AValues of non-zero elements
BColumn pointers marking start of each column in data array
CRow indices of non-zero elements
DTotal number of non-zero elements
✗ Incorrect
The 'indptr' array in CSC format shows where each column starts in the data array.
Which operation is CSC format especially efficient for?
ARow slicing and row-based matrix operations
BDense matrix multiplication
CColumn slicing and column-based matrix operations
DSorting matrix elements
✗ Incorrect
CSC format is designed to speed up column slicing and column-based operations.
In scipy, which function creates a CSC sparse matrix?
Ascipy.sparse.lil_matrix()
Bscipy.sparse.csr_matrix()
Cscipy.sparse.dok_matrix()
Dscipy.sparse.csc_matrix()
✗ Incorrect
The function scipy.sparse.csc_matrix() creates a CSC format sparse matrix.
What is stored in the 'data' array of a CSC matrix?
ANon-zero values of the matrix
BRow indices of non-zero values
CColumn pointers
DZero values
✗ Incorrect
The 'data' array holds the actual non-zero values of the sparse matrix.
Which format is better for fast row slicing?
ACSR (Compressed Sparse Row)
BCSC (Compressed Sparse Column)
CDense matrix
DDiagonal matrix
✗ Incorrect
CSR format compresses rows and is optimized for fast row slicing.
Explain how the CSC format stores a sparse matrix and why it is useful.
Think about how columns are compressed and what arrays are needed.
You got /6 concepts.
Describe the difference between CSC and CSR formats and when to use each.
Focus on which dimension is compressed and the typical operations.
You got /5 concepts.
Practice
(1/5)
1. What does the CSC format in scipy.sparse primarily store for a sparse matrix?
easy
A. Only non-zero values and their row indices, organized by columns
B. All values including zeros, organized by rows
C. Only zero values and their column indices
D. All values including zeros, organized by columns
Solution
Step 1: Understand CSC format storage
CSC stands for Compressed Sparse Column, which stores only non-zero values and their row indices, grouped by columns.
Step 2: Compare options with CSC definition
Only non-zero values and their row indices, organized by columns matches the CSC format definition exactly, while others include zeros or wrong organization.
Final Answer:
Only non-zero values and their row indices, organized by columns -> Option A
Quick Check:
CSC stores non-zero values by columns = A [OK]
Hint: CSC stores non-zero values by columns only [OK]
Common Mistakes:
Thinking CSC stores zero values
Confusing CSC with CSR (row-based)
Assuming all values are stored
2. Which of the following is the correct way to create a CSC matrix from a dense NumPy array arr in Python using SciPy?
easy
A. scipy.sparse.csc_matrix(arr)
B. scipy.sparse.csr_matrix(arr)
C. scipy.sparse.dense_matrix(arr)
D. scipy.sparse.csc(arr)
Solution
Step 1: Identify correct SciPy function for CSC
The function to create a CSC matrix is scipy.sparse.csc_matrix().
Step 2: Check options for syntax correctness
scipy.sparse.csc_matrix(arr) uses the correct function and syntax. scipy.sparse.csr_matrix(arr) creates CSR, not CSC. Options C and D are invalid functions.
Final Answer:
scipy.sparse.csc_matrix(arr) -> Option A
Quick Check:
Use csc_matrix() to create CSC format [OK]
Hint: Use csc_matrix() to create CSC sparse matrix [OK]
Common Mistakes:
Using csr_matrix instead of csc_matrix
Trying non-existent functions like dense_matrix
Missing _matrix suffix in function name
3. Given the following code, what will be the output of print(csc_matrix.indptr)?
C. Shape parameter is larger than input array size causing mismatch
D. csc_matrix requires data type float, not int
Solution
Step 1: Check input array and shape parameter
Input array is 2x2 but shape is set to 3x3, causing dimension mismatch.
Step 2: Understand effect of shape mismatch
Specifying a larger shape than data size is invalid and raises an error.
Final Answer:
Shape parameter is larger than input array size causing mismatch -> Option C
Quick Check:
Shape must match input size or smaller [OK]
Hint: Shape must match or be smaller than input array size [OK]
Common Mistakes:
Assuming lists are invalid input
Thinking data type must be float
Believing toarray() is missing
5. You have a large sparse matrix representing user-item ratings with mostly zeros. You want to efficiently compute the sum of ratings for each item (column). Which approach using CSC format is best?
hard
A. Convert to dense array and sum all values using np.sum()
B. Convert to CSC format and sum non-zero values column-wise using .sum(axis=0)
C. Convert to CSR format and sum non-zero values row-wise using .sum(axis=1)
D. Use COO format and iterate over all entries to sum columns manually
Solution
Step 1: Understand CSC format advantage
CSC stores data column-wise, making column operations like sum efficient.
Step 2: Choose best method for column sums
Using .sum(axis=0) on CSC matrix efficiently sums columns without converting to dense.
Final Answer:
Convert to CSC format and sum non-zero values column-wise using .sum(axis=0) -> Option B
Quick Check:
CSC + sum(axis=0) = fast column sums [OK]
Hint: Use CSC and sum(axis=0) for fast column sums [OK]
Common Mistakes:
Using CSR which is row-based for column sums
Converting to dense wastes memory
Manually iterating instead of vectorized sum
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.