[Numpy-discussion] extract elements of an array that are contained in another array?
josef.pktd@gmai...
josef.pktd@gmai...
Thu Jun 4 10:19:19 CDT 2009
On Thu, Jun 4, 2009 at 11:12 AM, Alan G Isaac <aisaac@american.edu> wrote:
>> 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...)
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@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the Numpy-discussion
mailing list