[Numpy-discussion] reduction

Charles R Harris charlesr.harris at gmail.com
Mon Jan 8 10:31:34 CST 2007


On 1/8/07, Charles R Harris <charlesr.harris at gmail.com> wrote:
>
>
>
> On 1/8/07, lorenzo bolla <lbolla at gmail.com> wrote:
> >
> > Hello all!
> > I'm fairly new to Numpy and, while experimenting, I found a strange (i.e.
> > not expected by me!) behaviour of arrays.
> > I tried this (in comment what I get):
> >
> > x = arange(4)      # x = array([0,1,2,3])
> >
> > def myadd(x,y):    # re-define the binary sum function
> >     return x + y
> >
> > reduce(myadd, x)     # 6, as expected
> >  add.reduce(x)     # 6, as expected
> >
> > def mysub(x,y):   # re-define the binary diff function
> >     return x - y
> >
> > reduce(mysub, x)    # -6, as expected
> > subtract.reduce(x)    # 2 ---> WHY?
> >
>
> It might be a bug in the implementation. What is happening is that instead
> of subtracting the new number from the previous result, the previous result
> is being subtracted from the new number. So you start with 0, and the
> sequence of operations continues:
>
> 0 = 0 - 0
> 1 = 1 - 0
> 1 = 2 - 1
> 2 = 3 - 1
> 2 = 4 - 2
> 3 = 5 - 2
>
> Definitely a bug. Want to file a ticket?
>

Or maybe not a bug. It depends on what reduce means for this operation. So
either a bug or something that could use a bit of documentation.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070108/9819c2f2/attachment.html 


More information about the Numpy-discussion mailing list