I need a weightened average function on a VERY large Dataset (some 1e8 numbers or more). The numpy functions mean and average serve me well and fast, but I discovered, that numpy.average is slower than builing the weightened average myself with two numpy.mean functions, as shown by the example:
https://gist.github.com/skuschel/2d148a37a2ce17925fb0
np.average(a,weights=b) takes 0.32 sec on my computer, but
np.mean(a*b)/np.mean(b) takes 0.23 sec for the equally sized dataset, yielding the same result.
How does that make sense?