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 x[i], I would like to compute:
n[i] = sum from j = 0 to n-1, j != i of (x[i]-x[j])^-2,
using numpy functions rather than looping. If there is a way to perform outer addition/multiplication:
m[i,j] = x[i]-x[j],
m[i,j] = x[i]*x[j],
I could use that to do the computation.