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><code>np.nonzero</code> will return the index information as a 1d tuple only. However, if you are looking for an alternative,Use <code>np.argwhere</code></p>

<pre><code>import numpy as np
l = np.array([0, 1, 2, 3, 0])
non_zero = np.argwhere(l!=0)
</code></pre>

<p>However, this will return a column matrix. To convert it to a row matrix,</p>

<pre><code>non_zero = non_zero.T[0]
</code></pre>

python arrays numpy shape zero