[Numpy-discussion] weights parameter of np.average() doesn't work (BUG?)

Daniel Lenski dlenski@gmail....
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 <dlenski@gmail.com> wrote:
> This has been fixed in later versions:
> In [2]: a=arange(100).reshape(10,10)
> In [3]: average(a, axis=1, weights=ones(10)) Out[3]: 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 mailing list