[Numpy-discussion] finding elements that match any in a set

Michael Katz michaeladamkatz at yahoo.com
Sun May 29 16:02:12 EDT 2011


Yes, in this case I definitely would have found in1d() if it was referenced in 
the where() section, either as a "see also" or even better as an example where 
where() is combined with np.in1d():


        indexes_of_interest = np.where( np.in1d( my_records.integer_field, 
my_values_of_interest ) )

I think the where() documentation page must be a place where a lot of 
people/newbies spend a lot of time. Perhaps like me they are focusing on the 
solution being "where() + some python stuff I already know", instead of thinking 
of other numpy functions, like in1d(), that might come into play.

It makes sense that in1d() is under the "Set" section. However (just to try to 
explain further why I didn't look and find it there), somehow I think of "set" 
when I am focused on having a list without duplicates. In my case I wasn't 
worried about duplicates, just about "I want all the guys that match any of 
these other guys". I did google for "numpy member", "numpy membership", "numpy 
in", but none led me to in1d().

Also, it's worth saying that, as a newcomer to numpy and relative newcomer to 
python, I often think that what I'm looking for isn't going to end up being a 
function with a name -- often some use of slices or (fancy) indexing, or some 
other "pure syntax" mechanism, ends up doing what you want. So that's one reason 
I didn't simply scan all the available numpy function names.



________________________________
From: Neil Crighton <neilcrighton at gmail.com>
To: numpy-discussion at scipy.org
Sent: Sun, May 29, 2011 10:03:25 AM
Subject: Re: [Numpy-discussion] finding elements that match any in a set

Michael Katz <michaeladamkatz <at> yahoo.com> writes:

> Yes, thanks, np.in1d is what I needed. I didn't know how to find that.

Did you check in the documentation? If so, where did you check? Would you have
found it if it was in the 'See also' section of where()?

(http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html)

I ask because people often post to the list needing in1d() after not being 
able to find it via the docs, so it would be nice to add references in
the places people go looking for it.

Neil


_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion at scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110529/c780ed11/attachment.html>


More information about the NumPy-Discussion mailing list