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