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

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Jun 4 11:19:19 EDT 2009


On Thu, Jun 4, 2009 at 11:12 AM, Alan G Isaac <aisaac at american.edu> wrote:
>> On Thu, Jun 4, 2009 at 10:13 AM, Alan G Isaac <aisaac at 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 at 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...)

Yes, I know, and in my current numpy help file this is the only
example there is, which is very misleading for its intended use.

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

>>> np.intersect1d_nu(a,b)
array([1, 4])

Josef

>
> Cheers,
> Alan
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list