title: Optimizing pairwise subtruction
body: <p>I have to compute the pairwise difference of particle's velocities for around 1e6 objects each with approx. 1e4 particles. Right now I am using itertools.combinations to loop over the particles, but just for one object my code takes already more than 30 minutes. I was wondering what else can I do to speed it up to a feasible speed, since parallelising doesn't seem to add much in python. Is cython the way to go?</p>
  
  <p>Here is my code just for one of the objects:</p>
  
  <pre><code>def pairwisevel(hist,velj,velk, xj, xk):
      vlos = (velj - velk) 
      if( (xj - xk) &lt; 0.):
          vlos = - vlos
      hist.add_from_value(vlos)
  
  
  for i in itertools.combinations(np.arange(0,int(particles_per_group[0]),1),2):
      pairwisevel(hist, pvel[i[0]], pvel[i[1]],\
                  pcoords[i[0]], pcoords[i[1]])
  </code></pre>