title: fastest way to iterate in python
body: <p>I've never had to concern myself with this problem so far but now I need to use some large number of vertices that need to be buffered by PyOpenGL and it seems like the python iteration is the bottleneck. Here is the situation. I have an array of 3D points <code>vertices</code>, and at each step I have to compute a 4D array of colors for each vertices. My approach so far is:</p>
  
  <pre><code>upper_border = len(self.vertices) / 3
  #Only generate at first step, otherwise use old one and replace values
  if self.color_array is None:
       self.color_array = numpy.empty(4 * upper_border)  
  
  for i in range(upper_border):
       #Obtain a color between a start-&gt;end color
       diff_activity = (activity[i] - self.min) / abs_diff  
       clr_idx = i * 4
       self.color_array[clr_idx] = start_colors[0] + diff_activity * end_colors[0]
       self.color_array[clr_idx + 1] = start_colors[1] + diff_activity * end_colors[1]
       self.color_array[clr_idx + 2] = start_colors[2] + diff_activity * end_colors[2]
       self.color_array[clr_idx + 3] = 1
  </code></pre>
  
  <p>Now I don't think there's anything else I can do to eliminate the operations from each step of the loop, but I'm guessing there has to be a more optimal performance way to do that loop. I'm saying that because in javascript for example, the same calculus produces a 9FPS while in Python I'm only getting 2-3 FPS.</p>
  
  <p>Regards,
  Bogdan</p>