I have data in XYZ type. For example:
x = numpy.arange(100)
y = numpy.arange(100)
Z = numpy.random.random_sample((100,))
I would like to bin data, for example, with overlap lengths of dx = 2
and dy = 2
. What I did is:
nx = len(x)
ny = len(y)
bin_data = np.zeros((nx, ny))
For i in range(nx):
For j in range(ny):
For a, b, c in zip(x,y,z):
if (x[i] < a) and (a < x[i] + dx):
if (y[j] < b) and (b < y[j] + dy):
bin_data[i,j] += c
For these small data program runs well. However it takes me too much time if the data are big. Can you please recommend any faster algorithm to bin data with overlapping in python. I know numpy.histogram2d
is quite fast, but it does not work for overlapping binning.