<p dir="auto">Hello,</p>
<p dir="auto">Recently I have been struggling with weird and unexpected behavior of numpy, and would like to have some help.</p>
<p dir="auto">Here is my code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
vec = np.random.uniform(-0.5, 0.5, size=(100)).astype(np.float32)
print(np.linalg.norm(vec))"><pre class="notranslate"><code class="notranslate">import numpy as np
vec = np.random.uniform(-0.5, 0.5, size=(100)).astype(np.float32)
print(np.linalg.norm(vec))
</code></pre></div>
<p dir="auto">This code returns very differently every run including</p>
<ol dir="auto">
<li><code class="notranslate">0.0</code></li>
<li><code class="notranslate">nan</code> along with <code class="notranslate">RuntimeWarning: invalid value encountered in sqrt</code></li>
<li>Very large value, i.e. <code class="notranslate">6074001000.0</code></li>
<li>Good value, i.e. <code class="notranslate">1.4142135</code></li>
</ol>
<p dir="auto">Further I confirmed that it works fine if I don't have <code class="notranslate">.astype</code>, but I need <code class="notranslate">vec</code> to be float32 for following process.</p>
<p dir="auto">My environment is</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="OS: macOS High Sierra
numpy version: 1.14.0
python version: anaconda3-5.1.0 (install with pyenv)"><pre class="notranslate"><code class="notranslate">OS: macOS High Sierra
numpy version: 1.14.0
python version: anaconda3-5.1.0 (install with pyenv)
</code></pre></div>
<p dir="auto">Thank you</p>
<p dir="auto">I am getting a different and incorrect value for the first element comparison when using the "assume_unique" option in numpy.in1d when comparing two 1D arrays.</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">mask = np.in1d(sum_array1, sum_array2)<br>
mask<br>
array([<strong>False</strong>, False, False, ...,  True, False, False], dtype=bool)</p>
<p dir="auto">mask = np.in1d(sum_array1, sum_array2, assume_unique=True)<br>
mask<br>
array([ <strong>True</strong>, False, False, ...,  True, False, False], dtype=bool)</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">NOTE: The first value in mask is incorrect when I used the "assume_unique" option. As far as I can tell the other values are ok.</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">sum_array1.shape<br>
(10000,)<br>
sum_array2.shape<br>
(200000,)<br>
sum_array1<br>
array([ 166.25097656, -131.        ,  -72.66274261, ..., -153.37646484,<br>
-154.26272583, -248.20391846], dtype=float32)<br>
sum_array2<br>
array([ -67.80783844, -155.38824463,   -6.23921967, ..., -290.447052  ,<br>
179.6862793 ,  205.69413757], dtype=float32)</p>
<p dir="auto">np.version.version<br>
'1.10.1'<br>
print(sys.version)<br>
2.7.6 (default, Jun 22 2015, 17:58:13)<br>
[GCC 4.8.2]</p>
</blockquote>
</blockquote>
<p dir="auto">lsb_release -a<br>
No LSB modules are available.<br>
Distributor ID: Ubuntu<br>
Description:    Ubuntu 14.04.2 LTS<br>
Release:    14.04<br>
Codename:   trusty</p>
</blockquote>