[Numpy-discussion] indexes in an array where value is greater than 1?

Chris Withers chris at simplistix.co.uk
Fri May 25 11:17:27 EDT 2012

Hi All,

I have an array:

arrrgh = numpy.zeros(100000000)

A sparse collection of elements will have values greater than zero:

arrrgh[9999] = 2
arrrgh[3453453] =42

The *wrong* way to do this is:

for i in xrange(len(arrrgh)):
     if arrrgh[i] > 1:
         print i

What's the right way?


Simplistix - Content Management, Batch Processing & Python Consulting
             - http://www.simplistix.co.uk

More information about the NumPy-Discussion mailing list