I have an array which looks like:
array([[ 1., 2., None],
[ nan, 4., 5.]])
I am trying the following:
np.equal(A, None) #works and finds index of None correctly
np.equal(A, np.nan) #doesn't work
np.isnan(A) #errors out
The error is:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
How should I approach this, I am trying to find the index of None and nan in a given array.
My final output should look as:
array([[False, False, True],
[True, False, False]], dtype=bool)
We could first cast the array to have dtype float — which will convert the None to NaN. numpy.isnan
can then be used on this float array.
numpy.isnan(A.astype(float))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With