[Numpy-discussion] member1d and unique elements

Stéfan van der Walt stefan@sun.ac...
Sun Aug 3 12:16:42 CDT 2008

2008/8/3 Greg Novak <novak@ucolick.org>:
> First of all, my desired operation is well-posed:  I'd like f(ar1,
> ar2) to return something in the shape of ar1 with True if the value at
> that position appears anywhere in ar2 (regardless of duplication) and
> False otherwise.

Just because one-liners are so irresistable:

>>> x
array([1, 1, 2, 5, 7])

>>> x2
array([1, 7])

>>> np.logical_or.reduce(x[:,None] == x2, axis=1)
array([ True,  True, False, False,  True], dtype=bool)

>>> (x[:,None] == x2).sum(axis=1) > 0
array([ True,  True, False, False,  True], dtype=bool)

Creates an MnX temporary, but oh well.

Thanks for taking a look at member1d. I'm swamped, so I cannot take
part in the conversation, but I hope someone takes note.  If no one
does, please file a ticket so that we don't lose track of this


More information about the Numpy-discussion mailing list