<p dir="auto">In Windows 10, when Numpy has overflow it shows a wrong number without error.</p>
<p dir="auto">In Linux it doesn't have this problem.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
a= [4, 7, 6, 5, 4, 5, 6, 8, 2, 8, 4, 8, 9]
print (np.prod(a))
&gt;&gt; -579076096"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">a</span><span class="pl-c1">=</span> [<span class="pl-c1">4</span>, <span class="pl-c1">7</span>, <span class="pl-c1">6</span>, <span class="pl-c1">5</span>, <span class="pl-c1">4</span>, <span class="pl-c1">5</span>, <span class="pl-c1">6</span>, <span class="pl-c1">8</span>, <span class="pl-c1">2</span>, <span class="pl-c1">8</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>, <span class="pl-c1">9</span>]
<span class="pl-en">print</span> (<span class="pl-s1">np</span>.<span class="pl-en">prod</span>(<span class="pl-s1">a</span>))
<span class="pl-c1">&gt;&gt;</span> <span class="pl-c1">-</span><span class="pl-c1">579076096</span></pre></div>
<p dir="auto">The correct one is</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
a= [4, 7, 6, 5, 4, 5, 6, 8, 2, 8, 4, 8, 9]
print (np.prod(a, dtype='int64'))
&gt;&gt; 23514624000"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">a</span><span class="pl-c1">=</span> [<span class="pl-c1">4</span>, <span class="pl-c1">7</span>, <span class="pl-c1">6</span>, <span class="pl-c1">5</span>, <span class="pl-c1">4</span>, <span class="pl-c1">5</span>, <span class="pl-c1">6</span>, <span class="pl-c1">8</span>, <span class="pl-c1">2</span>, <span class="pl-c1">8</span>, <span class="pl-c1">4</span>, <span class="pl-c1">8</span>, <span class="pl-c1">9</span>]
<span class="pl-en">print</span> (<span class="pl-s1">np</span>.<span class="pl-en">prod</span>(<span class="pl-s1">a</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'int64'</span>))
<span class="pl-c1">&gt;&gt;</span> <span class="pl-c1">23514624000</span></pre></div>
<p dir="auto">Numpy should show some errors of overflow<br>
<a href="https://stackoverflow.com/questions/55767586/numpy-array-prod-vs-multiply-list-items" rel="nofollow">Related issue</a></p>
<p dir="auto">This has come up before, but I'm not sure we have a canonical issue.</p>
<p dir="auto">Historically in python 2:</p>
<ul dir="auto">
<li><code class="notranslate">builtins.int</code> is mapped to <code class="notranslate">np.int_</code> (C <code class="notranslate">long</code>), since <code class="notranslate">builtins.int</code> is stored as a C <code class="notranslate">long</code></li>
<li><code class="notranslate">builtins.long</code> is mapped to <code class="notranslate">np.longlong</code> (C <code class="notranslate">long long</code>), since  <code class="notranslate">builtins.long</code> is infinite precision and that's the largest available integer type</li>
</ul>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# python 2.7
&gt;&gt;&gt; np.dtype(int).char
'l'
&gt;&gt;&gt; np.dtype(long).char
'q'"><pre class="notranslate"><span class="pl-c"># python 2.7</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">dtype</span>(<span class="pl-s1">int</span>).<span class="pl-s1">char</span>
<span class="pl-s">'l'</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">dtype</span>(<span class="pl-s1">long</span>).<span class="pl-s1">char</span>
<span class="pl-s">'q'</span></pre></div>
<p dir="auto">Note the above output only reflects the state of windows - other platforms have <code class="notranslate">sizeof(long) == sizeof(long long)</code>, so the distinction isn't important.</p>
<p dir="auto">In python 3, <code class="notranslate">builtins.int</code> has been removed, and <code class="notranslate">builtins.long</code> has been renamed to <code class="notranslate">__builtins__.int</code>. Yet:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# python 3.5
&gt;&gt;&gt; new_long = int
&gt;&gt;&gt; np.dtype(new_long).char
'l'  # smaller than it was on python 2"><pre class="notranslate"><span class="pl-c"># python 3.5</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">new_long</span> <span class="pl-c1">=</span> <span class="pl-s1">int</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">dtype</span>(<span class="pl-s1">new_long</span>).<span class="pl-s1">char</span>
<span class="pl-s">'l'</span>  <span class="pl-c"># smaller than it was on python 2</span></pre></div>
<p dir="auto">This means that python code translated from 2 to 3 by replacing <code class="notranslate">long</code> with <code class="notranslate">int</code> will start behaving differently:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# python 2
&gt;&gt;&gt; np.array(10**10, dtype=long)
array(10000000000L, dtype=int64)"><pre class="notranslate"><span class="pl-c"># python 2</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-c1">10</span><span class="pl-c1">**</span><span class="pl-c1">10</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">long</span>)
<span class="pl-en">array</span>(<span class="pl-c1">10000000000L</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int64</span>)</pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# python 3 translation
&gt;&gt;&gt; np.array(10**10, dtype=int)
OverflowError: Python int too large to convert to C long"><pre class="notranslate"><span class="pl-c"># python 3 translation</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-c1">10</span><span class="pl-c1">**</span><span class="pl-c1">10</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">int</span>)
<span class="pl-v">OverflowError</span>: <span class="pl-v">Python</span> <span class="pl-s1">int</span> <span class="pl-s1">too</span> <span class="pl-s1">large</span> <span class="pl-s1">to</span> <span class="pl-s1">convert</span> <span class="pl-s1">to</span> <span class="pl-v">C</span> <span class="pl-s1">long</span></pre></div>
<p dir="auto">Since this affects users transitioning from 2 to 3, I think it's important that we get it fixed in 1.16, which will be the last version that transitioning users can test both version of python against.</p>
<hr>
<p dir="auto">The current implementation, introduced in <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/numpy/numpy/commit/aa7be886274a6535169e5866383cc997231cf99d/hovercard" href="https://github.com/numpy/numpy/commit/aa7be886274a6535169e5866383cc997231cf99d"><tt>aa7be88</tt></a> by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pv/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pv">@pv</a>, is:</p>
<div class="highlight highlight-source-c notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#if !defined(NPY_PY3K)
        if (obj == (PyObject *)(&amp;PyInt_Type)) {
            check_num = NPY_LONG;
        }
        else if (obj == (PyObject *)(&amp;PyLong_Type)) {
            check_num = NPY_LONGLONG;
        }
#else
        if (obj == (PyObject *)(&amp;PyLong_Type)) {
            check_num = NPY_LONG;
        }
#endif"><pre class="notranslate"><span class="pl-k">#if</span> !defined(<span class="pl-c1">NPY_PY3K</span>)
        <span class="pl-k">if</span> (<span class="pl-s1">obj</span> <span class="pl-c1">==</span> (<span class="pl-smi">PyObject</span> <span class="pl-c1">*</span>)(<span class="pl-c1">&amp;</span><span class="pl-s1">PyInt_Type</span>)) {
            <span class="pl-s1">check_num</span> <span class="pl-c1">=</span> <span class="pl-c1">NPY_LONG</span>;
        }
        <span class="pl-k">else</span> <span class="pl-k">if</span> (<span class="pl-s1">obj</span> <span class="pl-c1">==</span> (<span class="pl-smi">PyObject</span> <span class="pl-c1">*</span>)(<span class="pl-c1">&amp;</span><span class="pl-s1">PyLong_Type</span>)) {
            <span class="pl-s1">check_num</span> <span class="pl-c1">=</span> <span class="pl-c1">NPY_LONGLONG</span>;
        }
<span class="pl-k">#else</span>
        <span class="pl-k">if</span> (<span class="pl-s1">obj</span> <span class="pl-c1">==</span> (<span class="pl-smi">PyObject</span> <span class="pl-c1">*</span>)(<span class="pl-c1">&amp;</span><span class="pl-s1">PyLong_Type</span>)) {
            <span class="pl-s1">check_num</span> <span class="pl-c1">=</span> <span class="pl-c1">NPY_LONG</span>;
        }
<span class="pl-k">#endif</span></pre></div>
<p dir="auto">I'd propose it should have been:</p>
<div class="highlight highlight-source-c notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#if !defined(NPY_PY3K)
        if (obj == (PyObject *)(&amp;PyInt_Type)) {
            check_num = NPY_LONG;
        }
        else
#endif 
        if (obj == (PyObject *)(&amp;PyLong_Type)) {
            check_num = NPY_LONGLONG;
        }"><pre class="notranslate"><span class="pl-k">#if</span> !defined(<span class="pl-c1">NPY_PY3K</span>)
        <span class="pl-k">if</span> (<span class="pl-s1">obj</span> <span class="pl-c1">==</span> (<span class="pl-smi">PyObject</span> <span class="pl-c1">*</span>)(<span class="pl-c1">&amp;</span><span class="pl-s1">PyInt_Type</span>)) {
            <span class="pl-s1">check_num</span> <span class="pl-c1">=</span> <span class="pl-c1">NPY_LONG</span>;
        }
        <span class="pl-k">else</span>
<span class="pl-k">#endif</span> 
        <span class="pl-k">if</span> (<span class="pl-s1">obj</span> <span class="pl-c1">==</span> (<span class="pl-smi">PyObject</span> <span class="pl-c1">*</span>)(<span class="pl-c1">&amp;</span><span class="pl-s1">PyLong_Type</span>)) {
            <span class="pl-s1">check_num</span> <span class="pl-c1">=</span> <span class="pl-c1">NPY_LONGLONG</span>;
        }</pre></div>
<p dir="auto">Ie, treating <code class="notranslate">PyLong_Type</code> in python 3 just as we always did in python 2.</p>