[Numpy-discussion] weights parameter of np.average() doesn't work (BUG?)
Charles R Harris
Mon Aug 25 00:44:28 CDT 2008
On Sun, Aug 24, 2008 at 9:56 PM, Daniel Lenski <email@example.com> wrote:
> On Sun, 24 Aug 2008 20:57:43 -0600, Charles R Harris wrote:
> On Sun, Aug 24, 2008 at 8:03 PM, Dan Lenski <firstname.lastname@example.org> 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.
I expect you can do this explicitly, which is pretty much what average does
anyway. Average is pure python, so you won't be losing any efficiency. If
you were a bit clearer with your use case I could be more explicit.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion