2D data binning with overlapping in python -


i have data in xyz type. example:

x = numpy.arange(100) y = numpy.arange(100) z = numpy.random.random_sample((100,)) 

i bin data, example, overlap lengths of dx = 2 , dy = 2. did is:

nx = len(x) ny = len(y) bin_data = np.zeros((nx, ny)) in range(nx):     j in range(ny):         a, b, c in zip(x,y,z):             if (x[i] < a) , (a < x[i] + dx):                 if (y[j] < b) , (b < y[j] + dy):                     bin_data[i,j] += c 

for these small data program runs well. takes me time if data big. can please recommend faster algorithm bin data overlapping in python. know numpy.histogram2d quite fast, not work overlapping binning.

i thing make algorythm faster moving zip outside of 2 other loops, imho longest operation :

for a, b, c in zip(x,y,z):     in range(nx):         j in range(ny):             ... 

then, in exemple, make use of x[i] == , y[j] == j (i add +1 because have strict <) :

for a, b, c in zip(x,y,z):     in range(a - dx + 1, a):         j in range(b - dy + 1, b):             bin_data[i,j] += c 

in fact, can second optimisation x = f(i) , y = g(i) f , g being monotonic , reversible giving = f-1(x) , j = g-1(y)


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -