私はpython / numpyで作業しています。入力データとして、多数の値のペアがあります(x,y)
。私は基本的に、特定のデータビン<y>(x)
の平均値をプロットしたいと考えています。現時点では、これを達成するために単純なループを使用していますが、これは非常に遅いです。y
x
for
# 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] ) ])
ある種のベクトル化された書き込みをすることは可能ですか?