title: How can I transform this (100, 100) numpy array into a grayscale sprite in pygame?
body: <p>I'm trying to make a special kind of grating called a Gabor patch, an example of which can be found at the bottom of <a href="http://www.icn.ucl.ac.uk/courses/MATLAB-Tutorials/Elliot_Freeman/html/gabor_tutorial.html" rel="nofollow noreferrer">this tutorial</a> whose code I ported to python.</p>
  
  <p>Using matplotlib's <code>imshow</code> function, I obtain the following patch.<img src="https://i.stack.imgur.com/oewfO.png" alt="python-generated Gabor patch displayed with matplotlib&#39;s imshow"></p>
  
  <p>While the coloring is different, I suspect that this has to do with how matplotlib displays numerical values.  In essence, this image is a 2D, 100-by-100 pixel array containing values from <code>-1.0</code> to <code>1.0</code> (inclusive).  If anybody would like to try manipulating the array in question, I've saved it as a pickle object <a href="https://dl.dropboxusercontent.com/u/6160029/g.pickle" rel="nofollow noreferrer">here</a>.</p>
  
  <p><strong>My question is as follows:</strong> How can I transfer this array to a pygame surface while ensuring that the following conditions are met?</p>
  
  <ol>
  <li>The coloring is converted to grayscale coloring (<em>c.f.</em>: the last image in the first link)</li>
  <li>The solution must employ pygame version <code>1.9.1release</code>.  For some inexplicable reason, I can't find a way to install <code>1.9.2</code> on my OS (Ubuntu 13.04).  There appear to be no PPAs and pygame is evidently not on PIP.</li>
  </ol>
  
  <p>Thank you very much in advance, and please let me know if I can provide additional information!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Regarding @Veedrac's solution (which is remarkably similar to my own), here is what my patch looks like when using the grayscale colormap in matplotlib's <code>imshow</code>.  This is what I <strong>would like</strong> to have:</p>
  
  <pre><code>from matplotlib.pyplot import *
  import matplotlib.cm as cm
  
  figure()
  imshow(g, cm=cm.Greys_r)
  show()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/jyzRe.png" alt="enter image description here"></p>