<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 14 April 2014 18:17, Alan G Isaac <span dir="ltr"><<a href="mailto:alan.isaac@gmail.com" target="_blank">alan.isaac@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I find it rather more convenient to use boolean arrays,<br>
but I wonder if arrays of indexes might have other<br>
advantages (which would suggest using the set operations<br>
instead). In particular, might a[boolean_array] be slower<br>
that a[indexes]?  (I'm just asking, not suggesting.)</blockquote></div><br></div><div class="gmail_extra">Indexing is generally faster, but convert from boolean to indexes gets more expensive:<br><br>In [2]: arr =np.random.random(1000)<br>

<br>In [3]: mask = arr>0.7<br><br>In [4]: mask.sum()<br>Out[4]: 290<br><br>In [5]: %timeit arr[mask]<br>100000 loops, best of 3: 4.01 µs per loop<br><br>In [6]: %%timeit<br>   ...: wh = np.where(mask)<br>   ...: arr[wh]<br>

   ...: <br>100000 loops, best of 3: 6.47 µs per loop<br><br>In [8]: wh = np.where(mask)<br><br>In [9]: %timeit arr[wh]<br>100000 loops, best of 3: 2.57 µs per loop<br><br>In [10]: %timeit np.where(mask)<br>100000 loops, best of 3: 3.89 µs per loop<br>

<br>In [14]: np.all(arr[wh] == arr[mask])<br>Out[14]: True<br><br><br></div><div class="gmail_extra">If you want to apply the same mask to several arrays, it is then worth (performance-wise) to do it.<br></div><div class="gmail_extra">

<br><br>/David.<br></div></div>