How do I return a nonflat numpy array selecting elements given a set of conditions?
<p>I have a multidimensional array, say of shape (4, 3) that looks like</p>

<pre><code>a = np.array([(1,2,3),(4,5,6),(7,8,9),(10,11,12)])
</code></pre>

<p>If I have a list of fixed conditions</p>

<pre><code>conditions = [True, False, False, True]
</code></pre>

<p>How can I return the list</p>

<pre><code>array([(1,2,3),(10,11,12)])
</code></pre>

<p>Using <code>np.extract</code> returns</p>

<pre><code>&gt;&gt;&gt; np.extract(conditions, a)
array([1, 4])
</code></pre>

<p>which only returns the first element along each nested array, as opposed to the array itself. I wasn't sure if or how I could do this with <code>np.where</code>. Any help is much appreciated, thanks!</p>

<p>you can use simple list slicing and <code>np.where</code> It's more or less made specifically for this situation..</p>

<pre><code>&gt;&gt;&gt; a[np.where(conditions)]
array([[[ 1,  2,  3],
        [10, 11, 12]]])
</code></pre>

python arrays numpy conditional slice