Numpy boolean indexing issue
<p>Here is my code snippet that uses numpy</p>

<pre><code>import numpy as np
n = 10
arr = np.array(range(n))
print(arr)
selection = [i % 2 == 0 for i in range(n)]
print(selection)
neg_selection = np.invert(selection)
print(neg_selection)

print(arr[selection])
print(arr[neg_selection])
</code></pre>

<p>The above code prints:</p>

<pre><code>[0 1 2 3 4 5 6 7 8 9]
[True, False, True, False, True, False, True, False, True, False]
[False  True False  True False  True False  True False  True]
[1 0 1 0 1 0 1 0 1 0]
[1 3 5 7 9]
</code></pre>

<p>the last two expected prints are:</p>

<pre><code>[0 2 4 6 8]
[1 3 5 7 9]
</code></pre>

<p>What is wrong here?</p>

<p>Note that you can (should) write:</p>

<pre><code>arr = np.arange(n) # elements of arr have the same type as n (int, float, complex, etc)
arr = np.arange(n, dtype=int)
arr = np.arange(n, dtype=float)
</code></pre>

<p>depending on what type you want for <code>arr</code>.</p>

python numpy