1 00:00:00,032 --> 00:00:05,060 So the traditional way to represent a sparse matrix is what we call compressed sparse row. 2 00:00:05,060 --> 00:00:08,156 So here's a small matrix of 9 elements. 3 00:00:08,156 --> 00:00:11,764 Three of them are zeroes, and so we want some sort of representation 4 00:00:11,764 --> 00:00:13,926 that's going to squeeze out those zeroes 5 00:00:13,926 --> 00:00:16,692 and only represent the values that are non-zero. 6 00:00:16,692 --> 00:00:19,303 And it seems a little silly on a small matrix like this, 7 00:00:19,303 --> 00:00:23,045 but, trust me, as you get to very large matrices with lots and lots of zeroes, 8 00:00:23,045 --> 00:00:27,703 this representation is going to save you a lot of space and save you a lot of computation. 9 00:00:27,703 --> 00:00:34,947 So in CSR format we require 3 vectors that together are going to represent this sparse matrix. 10 00:00:34,947 --> 00:00:37,446 So the first one is what we call the value vector, 11 00:00:37,446 --> 00:00:41,275 and it is simply going to represent all the non-zero data. 12 00:00:41,275 --> 00:00:46,447 So here we're simply going to list all the data that are not zero as 1 long array. 13 00:00:46,447 --> 00:00:51,196 The second array that we need is recording which column each of these data came from. 14 00:00:51,196 --> 00:01:00,429 So for instance, a is in column 0, b is in column 2, c is in column 0, and so on. 15 00:01:00,429 --> 00:01:05,711 And finally we have to indicate at which element each one of these 3 rows begin. 16 00:01:05,711 --> 00:01:12,756 So the 3 rows begin with value a and value c and value f. 17 00:01:12,756 --> 00:01:18,055 So what we're going to write in the row pointer is that value a is at index 0, 18 00:01:18,055 --> 00:01:23,300 value c is at index 2, and value f is at index 5. 19 00:01:23,300 --> 00:01:29,357 And now we can reconstruct this sparse matrix with these 3 arrays.