# [Numpy-discussion] effectively computing variograms with numpy

Hanno Klemm klemm@phys.ethz...
Fri Jun 22 08:29:56 CDT 2007

Hi,

I have an array which represents regularly spaced spatial data. I now
would like to compute the (semi-)variogram, i.e.

gamma(h) = 1/N(h) \sum_{i,j\in N(h)} (z_i - z_j)**2,

where h is the (approximate) spatial difference between the
measurements z_i, and z_j, and N(h) is the number of measurements with
distance h.

However, I only want to calculate the thing along the rows and
columns. The naive approach involves two for loops and a lot of
searching, which becomes painfully slow on large data sets. Are there
better implementations around in numpy/scipy or does anyone have a
good idea of how to do that more efficient? I looked around a bit but
couldn't find anything.

Hanno