[SciPy-user] Finding min/max indices satisfying a predicate

Daishi Harada daishi at egcrc.net
Mon Jun 7 18:28:05 CDT 2004


I am wondering if there is a canonical recipe for doing the following
efficiently/without using list comprehensions:

min_index = min([i for i in xrange(len(x)) if predicate(x[i])])

where x is some numarray. In particular I would be interested in some
mechanism which is O(min_index) instead of O(len(x)). (I am currently
using the naive basic python version of the O(min_index) search,
but was curious if there was something built in to scipy). FWIW, the
predicates that I am interested in are as simple as x[i] > 


More information about the SciPy-user mailing list