title: reduce time for a long for-loop in python
body: <p>a other stupid question from my side ;) I have some issues with the following snippet with len(x)=len(y)=7'700'000:</p>
  
  <pre><code>from numpy import *
  
  for k in range(len(x)):
      if x[k] == xmax:
          xind = -1
      else:
          xind = int(floor((x[k]-xmin)/xdelta))
      if y[k] == ymax:
          yind = -1
      else:
          yind = int(floor((y[k]-ymin)/ydelta))
  
      arr = append(arr,grid[xind,yind])
  </code></pre>
  
  <p>All variables are floats or integers except <code>arr</code> and <code>grid</code>. <code>arr</code> is a 1D-array and <code>grid</code> is a 2D-array.</p>
  
  <p>My problem is that it takes a long time to run through the loop (several minutes). Can anyone explain me, why this takes such a long time? Have anyone a suggestion? Even if I try to exchange <code>range()</code> through <code>arange()</code>then I save only some second.</p>
  
  <p>Thanks.</p>
  
  <p><strong>1st EDIT</strong>
  Sorry. Forgot to tell that I'm importing <code>numpy</code></p>
  
  <p><strong>2nd EDIT</strong></p>
  
  <p>I have some points in a 2D-grid. Each cell of the grid have a value stored. I have to find out which position the point have and apply the value to a new array. That's my problem and my idea.</p>
  
  <p>p.s.: look at the picture if you want to understand it better. the values of the cell are represented with different colors.</p>
  
  <p><img src="https://i.stack.imgur.com/5pdX5.png" alt="idea"></p>