<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/414" rel="nofollow">http://projects.scipy.org/numpy/ticket/414</a> on 2007-01-08 by trac user lbolla, assigned to unknown.</em></p>
<p dir="auto">[[BR]]<br>
Wrong results are given by subtract.reduce and divide.reduce, with respect to the standard function reduce.<br>
Take a look at this piece of code:</p>
<hr>
<p dir="auto">from numpy import *</p>
<p dir="auto">x = arange(4)            # x = array([0,1,2,3])</p>
<p dir="auto">def myadd(x,y):          # re-define the binary sum function</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="return x + y"><pre class="notranslate"><code class="notranslate">return x + y
</code></pre></div>
<p dir="auto">print reduce(myadd, x)   # 6, as expected</p>
<p dir="auto">print add.reduce(x)      # 6, as expected</p>
<p dir="auto">def mysub(x,y):          # re-define the binary diff function</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="return x - y"><pre class="notranslate"><code class="notranslate">return x - y
</code></pre></div>
<p dir="auto">print reduce(mysub, x)   # -6, as expected</p>
<p dir="auto">print subtract.reduce(x) # 2 ---&gt; WRONG!</p>
<hr>
<p dir="auto">It probably depends on the wrong order of the operands in the binary operation subtract or divide. Any non-commutative operation can lead to this problem (and it's worth checking!).<br>
This code works correctly if the Numeric package is imported istead of numpy (first row of the snippet).</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/413" rel="nofollow">http://projects.scipy.org/numpy/ticket/413</a> on 2007-01-08 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/rkern/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/rkern">@rkern</a>, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/teoliphant/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/teoliphant">@teoliphant</a>.</em></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [21]: import numpy

In [22]: numpy.subtract.reduce(numpy.arange(5))
Out[22]: 2

In [23]: import Numeric

In [24]: Numeric.subtract.reduce(Numeric.arange(5))
Out[24]: -10

In [25]: print numpy.__version__
1.0.2.dev3493

In [26]: print Numeric.__version__
24.2"><pre class="notranslate"><code class="notranslate">In [21]: import numpy

In [22]: numpy.subtract.reduce(numpy.arange(5))
Out[22]: 2

In [23]: import Numeric

In [24]: Numeric.subtract.reduce(Numeric.arange(5))
Out[24]: -10

In [25]: print numpy.__version__
1.0.2.dev3493

In [26]: print Numeric.__version__
24.2
</code></pre></div>