Getting the correct dimensions after using np.nonzero on array
<p>When using the the np.nonzero on a 1d array: </p>

<pre><code>l = np.array([0, 1, 2, 3, 0])
np.nonzero(l)
array([1,2,3], dtype=int64)
</code></pre>

<p>How do I get the index information as a 1d array and not as a tuple in the most effecient way? </p>

<p>You are looking for <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.flatnonzero.html" rel="nofollow"><code>np.flatnonzero</code></a> for use on a <code>1D</code> array -</p>

<pre><code>In [5]: l
Out[5]: array([0, 1, 2, 3, 0])

In [6]: np.flatnonzero(l)
Out[6]: array([1, 2, 3])
</code></pre>

python arrays numpy shape zero