Invert 0 and 1 in a binary array
<p>Is there a function in Numpy to invert 0 and 1 in a binary array?
If</p>

<pre><code>a = np.array([0, 1, 0, 1, 1])
</code></pre>

<p>I would like to get:</p>

<pre><code>b = [1, 0, 1, 0, 0]
</code></pre>

<p>I use:</p>

<pre><code>b[a==0] = 1
b[a==1] = 0
</code></pre>

<p>but maybe it already exist something in Numpy to do this.</p>

<p>A functional approach:</p>

<pre><code>&gt;&gt;&gt; np.logical_not(a).astype(int)
array([1, 0, 1, 0, 0])
</code></pre>

python numpy