<p dir="auto">When using <code class="notranslate">numpy.random.choice</code> to select one object from a list of large integers it sometimes transform the integer into a float losing the exact value of the integer.</p>
<p dir="auto"><strong>Reproducing code example:</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a =[2719731347783780899, 12101784904839573027]
result = np.random.choice(a, 1)[0]
print(type(result), result, int(result))"><pre lang="import" class="notranslate"><code class="notranslate">a =[2719731347783780899, 12101784904839573027]
result = np.random.choice(a, 1)[0]
print(type(result), result, int(result))
</code></pre></div>
<p dir="auto">This does not match the behaviour when using larger or smaller values, for example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="b = [98639646499002920190162389576535446980143321954085953494713932, 50562095890851553294979528226801422915940222716450081597866592]
c = [12341324134, 52341341312]
result2 = np.random.choice(b, 1)[0]
print(type(result2), result2)
result3 = np.random.choice(b, 1)[0]
print(type(result3), result3)"><pre lang="import" class="notranslate"><code class="notranslate">b = [98639646499002920190162389576535446980143321954085953494713932, 50562095890851553294979528226801422915940222716450081597866592]
c = [12341324134, 52341341312]
result2 = np.random.choice(b, 1)[0]
print(type(result2), result2)
result3 = np.random.choice(b, 1)[0]
print(type(result3), result3)
</code></pre></div>
<p dir="auto">Probable Cause of this behaviour:</p>
<p dir="auto">When calling <code class="notranslate"> np.random.choice()</code> on a list numpy first converts it into a <code class="notranslate">numpy.array</code> and it decides a different <code class="notranslate">dtype</code> for different sizes of integers, with the same examples as above, the</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a =[2719731347783780899, 12101784904839573027]
b = [98639646499002920190162389576535446980143321954085953494713932, 50562095890851553294979528226801422915940222716450081597866592]
c = [12341324134, 52341341312]
print(np.array(a).dtype, np.array(b).dtype, np.array(c).dtype)"><pre lang="import" class="notranslate"><code class="notranslate">a =[2719731347783780899, 12101784904839573027]
b = [98639646499002920190162389576535446980143321954085953494713932, 50562095890851553294979528226801422915940222716450081597866592]
c = [12341324134, 52341341312]
print(np.array(a).dtype, np.array(b).dtype, np.array(c).dtype)
</code></pre></div>
<p dir="auto">The results are <code class="notranslate">dtype('float64')</code>, <code class="notranslate">dtype('O')</code> and <code class="notranslate">dtype('int64')</code>. I understand that there is a limit of size on dtype('int64') but I would not expect numpy to transform integers into floats because it does not maintain the initial value, I would expect it to transform it into a python object.</p>
<p dir="auto">Python 3.7.2 (default, Jun 25 2019, 20:08:50)<br>
[GCC 6.3.0 20170516] on linux<br>
Type "help", "copyright", "credits" or "license()" for more information.</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">import numpy<br>
Traceback (most recent call last):<br>
File "/usr/local/lib/python3.7/site-packages/numpy/core/<strong>init</strong>.py", line 17, in <br>
from . import multiarray<br>
File "/usr/local/lib/python3.7/site-packages/numpy/core/multiarray.py", line 14, in <br>
from . import overrides<br>
File "/usr/local/lib/python3.7/site-packages/numpy/core/overrides.py", line 7, in <br>
from numpy.core._multiarray_umath import (<br>
ImportError: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.27' not found (required by /usr/local/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-arm-linux-gnueabihf.so)</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">During handling of the above exception, another exception occurred:</p>
<p dir="auto">Traceback (most recent call last):<br>
File "&lt;pyshell#0&gt;", line 1, in <br>
import numpy<br>
File "/usr/local/lib/python3.7/site-packages/numpy/<strong>init</strong>.py", line 142, in <br>
from . import core<br>
File "/usr/local/lib/python3.7/site-packages/numpy/core/<strong>init</strong>.py", line 47, in <br>
raise ImportError(msg)<br>
ImportError:</p>
<p dir="auto">IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!</p>
<p dir="auto">Importing the numpy c-extensions failed.</p>
<ul dir="auto">
<li>
<p dir="auto">Try uninstalling and reinstalling numpy.</p>
</li>
<li>
<p dir="auto">If you have already done that, then:</p>
<ol dir="auto">
<li>Check that you expected to use Python3.7 from "/usr/local/bin/python3.7",<br>
and that you have no directories in your PATH or PYTHONPATH that can<br>
interfere with the Python and numpy version "1.17.2" you're trying to use.</li>
<li>If (1) looks fine, you can open a new issue at<br>
<a href="https://github.com/numpy/numpy/issues">https://github.com/numpy/numpy/issues</a>.  Please include details on:
<ul dir="auto">
<li>how you installed Python</li>
<li>how you installed numpy</li>
<li>your operating system</li>
<li>whether or not you have multiple versions of Python installed</li>
<li>if you built from source, your compiler versions and ideally a build log</li>
</ul>
</li>
</ol>
</li>
<li>
<p dir="auto">If you're working with a numpy git repository, try <code class="notranslate">git clean -xdf</code><br>
(removes all files not under version control) and rebuild numpy.</p>
</li>
</ul>
<p dir="auto">Note: this error has many possible causes, so please don't comment on<br>
an existing issue about this - open a new one instead.</p>
<p dir="auto">Original error was: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.27' not found (required by /usr/local/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-arm-linux-gnueabihf.so)</p>
<p dir="auto">================================================<br>
Using Raspbian, I have multiple versions of python, I used<br>
<code class="notranslate">pi@raspberrypi:~ $ sudo python3.7 -m pip install numpy</code></p>