On 1/8/07, Charles R Harris <[EMAIL PROTECTED]> wrote:
On 1/8/07, lorenzo bolla <[EMAIL PROTECTED]> 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
_______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
