[Numpy-discussion] searchsorted for exact matches, not preserving order
Andrew Jaffe
a.h.jaffe@gmail....
Fri Sep 11 15:46:40 CDT 2009
On 11/09/2009 08:33, Robert Kern wrote:
> On Fri, Sep 11, 2009 at 10:24, Andrew Jaffe<a.h.jaffe@gmail.com> wrote:
>> Dear all,
>>
>> I've got two (integer) arrays, and I want to find the indices in the
>> first one that have entries in the second. I.E. I want all idx s.t.
>> there exists a j with a[idx]=b[j]. Here is my current implementation
>> (with a = pixnums, b=surveypix)
>
> numpy.setmember1d() [or numpy.in1d() for the SVN trunk of numpy].
>
Robert,
Thanks. But in fact this fails for my (possibly corner or edge) case:
when the first array has duplicates that, in fact, are not in the second
array, indices corresponding to those entries get returned. In general,
duplicates are not necessarily treated right by this algorithm, I don't
think.
I can understand that this may be a feature, not a bug, but in fact for
my use-case I want the algorithm to return the indices corresponding to
all entries in ar1 with the same value, if that value appears anywhere
in ar2.
Yours,
Andrew
More information about the NumPy-Discussion
mailing list