I'm being driven crazy by a NumPy array of dtype obj
with a missing value (in the example below, it is the penultimate value).
>> a
array([0, 3, 'Braund, Mr. Owen Harris', 'male', 22.0, 1, 0, 'A/5 21171',
7.25, nan, 'S'], dtype=object)
I want to find this missing value programatically with a function that returns a boolean vector with True
values in elements that correspond to missing values in the array (as per the example below).
>> some_function(a)
array([False, False, False, False, False, False, False, False, False, True, False],
dtype=bool)
I tried isnan
to no avail.
>> isnan(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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''
I also attempted performing the operation explicitly over every element of the array with apply_along_axis
, but the same error is returned.
>> apply_along_axis(isnan, 0, a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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''
Can anyone explain to me (1) what I'm doing wrong and (2) what I can do to solve this problem? From the error, I gather that it has to do with one of the elements not being in an appropriate type. What is the easiest way to get around this issue?