[Numpy-discussion] extract elements of an array that are contained in another array?
cimrman3 at ntc.zcu.cz
Fri Jun 5 01:48:37 EDT 2009
josef.pktd at gmail.com wrote:
> 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
>> 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"
I am bad in choosing names, but note that numpy sub-modules usually do
not use underscores, so array_set_ops would not fit well.
> BTW, for the docs, I haven't found a counter example where
> np.setdiff1d gives the wrong answer for non-unique arrays.
In : np.setmember1d( [1, 1, 2, 4, 2], [3, 2, 4] )
Out: array([ True, False, True, True, True], dtype=bool)
More information about the NumPy-Discussion