title: Python - efficient representation of pixels and associated values
body: <p>I'm using python to work with large-ish (approx 2000 x 2000) matrices, where each <code>I</code>, <code>J</code> point in the matrix represents a single pixel.</p>
  
  <p>The matrices themselves are sparse (ie a substantial portion of them will have zero values), but when they are updated they tend to be increment operations, to a large number of adjacent pixels in a rectangular 'block', rather than random pixels here or there (a property i do not currently use to my advantage..). 
  Afraid a bit new to matrix arithmetic, but I've looked into a number of possible solutions, including the various flavours of <code>scipy</code> sparse matrices. So far co-ordinate (COO) matrices seem to be the most promising. 
  So for instance where I want to increment one block shape, I'd have to do something along the lines of:</p>
  
  <pre><code>&gt;&gt;&gt; from scipy import sparse
  &gt;&gt;&gt; from numpy import array
  &gt;&gt;&gt; I = array([0,0,0,0])
  &gt;&gt;&gt; J = array([0,1,2,3])
  &gt;&gt;&gt; V = array([1,1,1,1])
  &gt;&gt;&gt; incr_matrix = sparse.coo_matrix((V,(I,J)),shape=(100,100))
  &gt;&gt;&gt; main_matrix += incr_matrix  #where main_matrix was previously defined
  </code></pre>
  
  <p>In the future, i'd like to have a richer pixel value representation in anycase (tuples to represent RGB etc), something that numpy array doesnt support out of the box (or perhaps I need to use <a href="http://mail.scipy.org/pipermail/numpy-discussion/2009-April/041801.html" rel="nofollow">this</a>). </p>
  
  <p>Ultimately i'll have a number of these matrices that I would need to do simple arithmitic on, and i'd need the code to be as efficient as possible -- and distributable, so i'd need to be able to persist and exchange these objects in a small-ish representation without substantial penalties. I'm wondering if this is the right way to go, or should I be looking rolling my own structures using <code>dicts</code> etc?</p>