[Numpy-discussion] extract elements of an array that are contained in another array?

Kim Hansen slaunger at gmail.com
Thu Jun 4 16:27:11 EDT 2009

Concerning the name setmember1d_nu, I personally find it quite verbose
and not the name I would expect as a non-insider coming to numpy and
not knowing all the names of the more special hidden-away functions
and not being a python-wiz either.

I think ain(a,b) would be the name I had expected as an array
equivalent of "a in b" (just as arange is the array version of range)
or I would had anticipated that an ndarray object would have an
"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

When I had a problem where I needed this function, I could not find
anything near that, and after looking around and also asking here I
got some hints to use the ....1d functions, which gave me the idea to
implement the few-line, very simple proposal for "a in b", which is
now the proposal under review as the new function setmember1d_nu(a,b).
Whereas I see this function name is in line with the existing
functions, I really think the names are non-intuitive. I would
therefore propose that it was also aliased to a more intuitive name
such as ain(a,b) or perhaps better a.in(b)

Again, I am probably missing some important points here as a
non-experienced Python programmer and numpy user, I am just trying to
give some input from the beginners point-of-view, if that can be of
any help.

Thank you,


More information about the NumPy-Discussion mailing list