[SciPy-User] faster nonzero indices

Felix Schlesinger schlesin@cshl....
Tue Oct 20 23:02:53 CDT 2009


Is there a faster way to do:

foo = scipy.nonzero(bar > 1)[0]

where bar is a 1d ndarray of type 'int32'
i.e. to get all indices of an array for which a condition is true.
 
Since in this case the arrays are quite large and the condition is only true for
few items creating a long boolean array and then passing over it again to find
non zero entries seems inefficient.

Felix



More information about the SciPy-User mailing list