[Numpy-discussion] reduction
Charles R Harris
charlesr.harris at gmail.com
Mon Jan 8 10:25:06 CST 2007
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?
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070108/14740368/attachment.html
More information about the Numpy-discussion
mailing list