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

Alan G Isaac aisaac@american....
Thu Jun 4 10:12:17 CDT 2009


> On Thu, Jun 4, 2009 at 10:13 AM, Alan G Isaac <aisaac@american.edu> wrote:
>> Or if a stable order is not important (I don't
>> recall if the OP specified), one could just
>> np.intersect1d(a, np.unique(b))

On 6/4/2009 10:50 AM josef.pktd@gmail.com apparently wrote:
> This requires that also `a` has only unique elements.
> intersect1d_nu doesn't require unique elements.


>>> a
array([1, 1, 2, 3, 3, 4])
>>> b
array([1, 4])
>>> np.intersect1d(a, np.unique(b))
array([1, 1, 3, 4])

(And thus my question about intersect1d...)

Cheers,
Alan



More information about the Numpy-discussion mailing list