I am working with python / numpy. As input, I have a large number of pairs of values (x,y) . I basically want to build <y>(x) , i.e. The average y for a specific data buffer x . Right now I'm using a simple for loop to achieve this, which is very slow.
# create example data x = numpy.random.rand(1000) y = numpy.random.rand(1000) # set resolution xbins = 100 # find x bins H, xedges, yedges = numpy.histogram2d(x, y, bins=(xbins,xbins) ) # calculate mean and std of y for each x bin mean = numpy.zeros(xbins) std = numpy.zeros(xbins) for i in numpy.arange(xbins): mean[i] = numpy.mean(y[ numpy.logical_and( x>=xedges[i], x<xedges[i+1] ) ]) std[i] = numpy.std (y[ numpy.logical_and( x>=xedges[i], x<xedges[i+1] ) ])
Is it possible to have some kind of vectorized record for him?
source share