[Numpy-discussion] weights parameter of np.average() doesn't work (BUG?)
Sun Aug 24 22:56:08 CDT 2008
On Sun, 24 Aug 2008 20:57:43 -0600, Charles R Harris wrote:
On Sun, Aug 24, 2008 at 8:03 PM, Dan Lenski <email@example.com> wrote:
> This has been fixed in later versions:
> In : a=arange(100).reshape(10,10)
> In : average(a, axis=1, weights=ones(10)) Out: array([ 4.5,
> 14.5, 24.5, 34.5, 44.5, 54.5, 64.5, 74.5, 84.5, 94.5])
Ah, good to know! I guess it's time to upgrade.
> However, broadcasting in the axis=None case is not allowed. The thinking
> is that the weights must be fully specified for the axis (or None) that
> is being averaged over.
Hmm, that's a pity :-(
My real-world use case has a 2D array of weights, shape (a,b), that I'd
like to broadcast to a 3D array, shape (n,a,b), which I average over the
first dimension. Currently, I just use repeat() to make it the right
size... but this is less-than-ideal for huge arrays.
More information about the Numpy-discussion