[Numpy-discussion] Find first occurrence?
Wed Sep 19 19:37:43 CDT 2007
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) 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...)
Program in Biomedical Informatics and Department of Biochemistry
More information about the Numpy-discussion