[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 16:43:39 EDT 2009


On Thu, Jun 4, 2009 at 4:30 PM, Gael Varoquaux
<gael.varoquaux at normalesup.org> wrote:
> On Thu, Jun 04, 2009 at 10:27:11PM +0200, Kim Hansen wrote:
>> "in(b)" or "in_iterable(b)" method, such that you could do a.in(b)
>> which would return a boolean array of the same shape as a with
>> elements true if the equivalent a members were members in the iterable
>> b.
>
> That would really by what I would be looking for.
>

Just using "in" might promise more than it does, eg. it works only for
one dimensional arrays, maybe "in1d". With "in", I would expect a
generic function as in python that works with many array types and
dimensions. (But I haven't checked whether it would work with a 1d
structured array or object array.)

I found arraysetops because of unique1d, but I didn't figure out what
the subpackage really does, because I was reading "arrayse-tops"
instead of array-set-ops"

BTW, for the docs, I haven't found a counter example where
np.setdiff1d gives the wrong answer for non-unique arrays.

Josef



More information about the NumPy-Discussion mailing list