0:00:00.032,0:00:05.060
So the traditional way to represent a sparse matrix is what we call compressed sparse row.
0:00:05.060,0:00:08.156
So here's a small matrix of 9 elements.
0:00:08.156,0:00:11.764
Three of them are zeroes, and so we want some sort of representation
0:00:11.764,0:00:13.926
that's going to squeeze out those zeroes
0:00:13.926,0:00:16.692
and only represent the values that are non-zero.
0:00:16.692,0:00:19.303
And it seems a little silly on a small matrix like this,
0:00:19.303,0:00:23.045
but, trust me, as you get to very large matrices with lots and lots of zeroes,
0:00:23.045,0:00:27.703
this representation is going to save you a lot of space and save you a lot of computation.
0:00:27.703,0:00:34.947
So in CSR format we require 3 vectors that together are going to represent this sparse matrix.
0:00:34.947,0:00:37.446
So the first one is what we call the value vector,
0:00:37.446,0:00:41.275
and it is simply going to represent all the non-zero data.
0:00:41.275,0:00:46.447
So here we're simply going to list all the data that are not zero as 1 long array.
0:00:46.447,0:00:51.196
The second array that we need is recording which column each of these data came from.
0:00:51.196,0:01:00.429
So for instance, a is in column 0, b is in column 2, c is in column 0, and so on.
0:01:00.429,0:01:05.711
And finally we have to indicate at which element each one of these 3 rows begin.
0:01:05.711,0:01:12.756
So the 3 rows begin with value a and value c and value f.
0:01:12.756,0:01:18.055
So what we're going to write in the row pointer is that value a is at index 0,
0:01:18.055,0:01:23.300
value c is at index 2, and value f is at index 5.
0:01:23.300,0:01:29.357
And now we can reconstruct this sparse matrix with these 3 arrays.