Thanks! Tried it and it is about twice as fast as my approach.<br><br>-Ning<br><br><div class="gmail_quote">On Wed, Jun 3, 2009 at 7:45 PM, <span dir="ltr"><<a href="mailto:josef.pktd@gmail.com">josef.pktd@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">On Wed, Jun 3, 2009 at 8:29 PM, Ning Sean <<a href="mailto:ningsean@gmail.com">ningsean@gmail.com</a>> wrote:<br>
> Hi, I want to extract elements of an array (say, a) that are contained in<br>
> another array (say, b). That is, if a=array([1,1,2,3,3,4]), b=array([1,4]),<br>
> then I want array([1,1,4]).<br>
><br>
> I did the following but the speed is very slow (maybe because a is very<br>
> long):<br>
><br>
> c=array([])<br>
> for x in b:<br>
> c=append(c,a[a==x])<br>
><br>
> any way to speed it up?<br>
><br>
> Thanks!<br>
> -Ning<br>
><br>
<br>
<br>
</div></div>It's waiting in Trac for inclusion in numpy<br>
<a href="http://projects.scipy.org/numpy/ticket/1036" target="_blank">http://projects.scipy.org/numpy/ticket/1036</a><br>
The current version only handles arrays with unique elements.<br>
<br>
You can copy the ticket attachment, the version there is very fast.<br>
<br>
Josef<br>
_______________________________________________<br>
Numpy-discussion mailing list<br>
<a href="mailto:Numpy-discussion@scipy.org">Numpy-discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br><br clear="all"><br>