Is there a way to find the indices where exceptions are thrown using np.where
?
For example:
a = np.array(['0.0', 'hi', '2012:13', '2013/04/05', '9.8', '7.6'])
print np.where(np.float64(a)==Exception)[0][-1]
I would hope would provide this output:
[ 0. 4. 5.]
However, it gives this output:
ValueError: could not convert string to float: hi
This script can provide the answer, but it seems quite inefficient and much less pythonic:
b = np.array([])
for i, x in enumerate(a):
try:
np.float64(x)
except:
b = np.hstack((b,i))
print b