title: Converting a nested loop calculation to Numpy for speedup
body: <p>Part of my Python program contains the follow piece of code, where a new grid
  is calculated based on data found in the old grid.</p>
  
  <p>The grid i a two-dimensional list of floats. The code uses three for-loops:</p>
  
  <pre><code>for t in xrange(0, t, step):
      for h in xrange(1, height-1):
          for w in xrange(1, width-1):
              new_gr[h][w] = gr[h][w] + gr[h][w-1] + gr[h-1][w] + t * gr[h+1][w-1]-2 * (gr[h][w-1] + t * gr[h-1][w])
      gr = new_gr
  
  return gr
  </code></pre>
  
  <p>The code is extremly slow for a large grid and a large time <em>t</em>.</p>
  
  <p>I've tried to use Numpy to speed up this code, by substituting the inner loop
  with:</p>
  
  <pre><code>J = np.arange(1, width-1)
  new_gr[h][J] = gr[h][J] + gr[h][J-1] ...
  </code></pre>
  
  <p>But the results produced (the floats in the array) are about 10% smaller than
  their list-calculation counterparts.</p>
  
  <ul>
  <li><p>What loss of accuracy is to be expected when converting lists of floats to Numpy array of floats using <em>np.array(pylist)</em> and then doing a calculation?</p></li>
  <li><p>How should I go about converting a triple for-loop to pretty and fast Numpy code? (or are there other suggestions for speeding up the code significantly?)</p></li>
  </ul>