[Numpy-discussion] Searching object arrays

Martin Spacek numpy at mspacek.mm.st
Mon May 7 19:43:40 EDT 2007


I want to find the indices of all the None objects in an object array:

 >> import numpy as np
 >> i = np.array([0, 1, 2, None, 3, 4, None])
 >> np.where(i == None)
()

Using == doesn't work the same way on object arrays as it does on, say, 
an array of int32. Any suggestions? Do I have to use a loop or list 
comprehension, like this?

 >> [ ii for (ii, id) in enumerate(i) if id == None ]

Thanks,

Martin



More information about the NumPy-Discussion mailing list