## ← Sparse Matrices - Intro to Parallel Programming

• 4 Followers
• 17 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=Lhef_jxzqCg" data-team="udacity"></div> ``` 2 Languages

Showing Revision 1 created 02/23/2013 by Cogi-Admin.

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