<br><br><div><span class="gmail_quote">On 1/8/07, <b class="gmail_sendername">Charles R Harris</b> <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div><span class="q"><span class="gmail_quote">On 1/8/07, <b class="gmail_sendername">lorenzo bolla</b> <<a href="mailto:lbolla@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
lbolla@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Hello all!</div>
<div>I'm fairly new to Numpy and, while experimenting, I found a strange (i.e. not expected by me!) behaviour of arrays.</div>
<div>I tried this (in comment what I get):</div>
<div> </div>
<div>x = arange(4)      # x = array([0,1,2,3])</div>
<div> </div>
<div>def myadd(x,y):    # re-define the binary sum function</div>
<div>    return x + y</div>
<div> </div>
<div>reduce(myadd, x)     # 6, as expected</div>
<div>
<div>add.reduce(x)     # 6, as expected</div>
<div> </div></div>
<div>def mysub(x,y):   # re-define the binary diff function</div>
<div>    return x - y</div>
<div> </div>
<div>reduce(mysub, x)    # -6, as expected</div>
<div>subtract.reduce(x)    # 2 ---> WHY?</div></blockquote></span><div><br>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:
<br><br>0 = 0 - 0<br>1 = 1 - 0<br>1 = 2 - 1<br>2 = 3 - 1<br>2 = 4 - 2<br>3 = 5 - 2<br><br>Definitely a bug. Want to file a ticket?</div></div></blockquote><div><br>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.
<br><br>Chuck<br></div></div><br>