[Numpy-discussion] Apply a function to all indices

Ole Streicher ole-usenet-spam at gmx.net
Fri Feb 26 07:31:41 EST 2010


Hello Ernest,

Ernest Adrogué <eadrogue at gmx.net> writes:
> It depends on what exactly you want to do. If you just want
> to iterate over the array, try something liks this
> for element in a[a > 0.8]:
> 	myfunc(element)

No; I need to iterate over the *indices*, not over the elements.

a = numpy.random.random((2,3,4))

for index in ???(a > 0.5):
    print index[0], index[1], index[2]

Best regards

Ole




More information about the NumPy-Discussion mailing list