[Numpy-discussion] Find first occurrence?
Zachary Pincus
zpincus at stanford.edu
Wed Sep 19 20:37:43 EDT 2007
Hello all,
On several occasions, I've had the need to find only the first
occurrence of a value in an unsorted numpy array. I usually use
numpy.where(arr==val)[0] or similar, and don't worry about the fact
that I'm iterating across the entire array.
However, sometimes the arrays are pretty big and the find operation
is in an inner loop, so I was wondering if there's already a C
extension function somewhere in numpy or scipy that does a fast find
first operation, or anything similar. (Easy enough to write my own,
and maybe given the issues inherent in comparing float equality,
etc., it doesn't belong in the core numpy anyway...)
Thanks,
Zach Pincus
Program in Biomedical Informatics and Department of Biochemistry
More information about the NumPy-Discussion
mailing list