-
Notifications
You must be signed in to change notification settings - Fork 0
Compressed Sparse Row
Roberto Fronteddu edited this page Jun 9, 2026
·
1 revision
The Compressed Sparse Row (CSR) format is a highly efficient way to represent matrices or datasets containing mostly zeros.
CSR represents a dataset using three distinct, one-dimensional arrays: the Values array, the Column Indices array, and the Row Offsets array.
- Values (or Data): An array containing all the non-zero elements of the dataset, listed sequentially in row-major order (reading row by row from left to right).
- Column Indices: An array that indicates the exact column location for each corresponding value in the Values array.
- Row Offsets (or Pointers): An array that acts as a guide. It shows the exact index in the Values array where each row begins and ends. Its length is always the total number of rows plus one.
Imagine a 3x3 matrix that is mostly zeros:
0 0 5
1 0 0
0 9 0
- Values: [5, 1, 9] (The non-zero numbers)
- Column Indices: [2, 0, 1] (5 is in column 2, 1 is in column 0, and 9 is in column
- Row Offsets: [0, 1, 2, 3] (Row 0 starts at index 0, Row 1 starts at index 1, Row 2 starts at index 2, and the total count of non-zeros is 3)