Indexing an array with a logical array of the same shape in Python
<p>I would like to be able to do:</p>

<pre><code>a = [1,2,3]
a[[True, True, False]]
&gt;&gt; array([1,2])
</code></pre>

<p>I just can't find the simple way how... Thanks!</p>

<p>You can play with built-in <code>filter</code> and <code>map</code></p>

<pre><code>k = [True, True, False, True]
l = [1,2,3,4]

print map(lambda j: j[1], filter(lambda i: i[0], zip(k,l)))
</code></pre>

python