[Numpy-discussion] extract elements of an array that are contained in another array?

Ning Sean ningsean@gmail....
Wed Jun 3 23:32:31 CDT 2009


Thanks! Tried it and it is about twice as fast as my approach.

-Ning

On Wed, Jun 3, 2009 at 7:45 PM, <josef.pktd@gmail.com> wrote:

> On Wed, Jun 3, 2009 at 8:29 PM, Ning Sean <ningsean@gmail.com> wrote:
> > Hi, I want to extract elements of an array (say, a) that are contained in
> > another array (say, b). That is, if a=array([1,1,2,3,3,4]),
> b=array([1,4]),
> > then I want array([1,1,4]).
> >
> > I did the following but the speed is very slow (maybe because a is very
> > long):
> >
> > c=array([])
> > for x in b:
> >    c=append(c,a[a==x])
> >
> > any way to speed it up?
> >
> > Thanks!
> > -Ning
> >
>
>
> It's waiting in Trac for inclusion in numpy
> http://projects.scipy.org/numpy/ticket/1036
> The current version only handles arrays with unique elements.
>
> You can copy the ticket attachment, the version there is very fast.
>
> Josef
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090603/ba2bd3b0/attachment.html 


More information about the Numpy-discussion mailing list