title: performing outer addition with numpy
body: <p>Sorry if this is a silly question but I am just getting started with python/numpy and I'm really not sure of the most efficient ways to go about things. I'm putting together a demo N-body simulator for some students, but for now, I am computing the force between particles by looping over the positions of those particles which is predictably as slow as molasses. Basically, given a vector <code>x[i]</code>, I would like to compute:</p>
  
  <pre><code>n[i] = sum from j = 0 to n-1, j != i of (x[i]-x[j])^-2,
  </code></pre>
  
  <p>using numpy functions rather than looping. If there is a way to perform outer addition/multiplication:</p>
  
  <pre><code>m[i,j] = x[i]-x[j],
  
  m[i,j] = x[i]*x[j],
  </code></pre>
  
  <p>I could use that to do the computation.</p>