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

josef.pktd@gmai... josef.pktd@gmai...
Thu Jun 4 07:35:05 CDT 2009


On Thu, Jun 4, 2009 at 8:23 AM, Alan G Isaac <aisaac@american.edu> wrote:
> a[(a==b[:,None]).sum(axis=0,dtype=bool)]

this is my preferred way when b is small and has unique elements.
if the elements in b are not unique, then be can be replaced by np.unique(b)
If b is large this creates a huge intermediate array

The advantage of the new setmember1d_nu is that it handles large b
very efficiently. My try on it was more than 10 times slower than the
proposed solution for larger arrays.

Josef

> hth,
> Alan Isaac


More information about the Numpy-discussion mailing list