我有一个数组,长这样:
array([[ 1., 2., None],
[ nan, 4., 5.]])
我正在尝试以下操作:
np.equal(A, None) #works and finds index of None correctly
np.equal(A, np.nan) #doesn't work
np.isnan(A) #errors out
错误信息为:
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''
我该如何处理这个问题,我正在尝试在给定的数组中找到None和nan的索引。
我的最终输出应该如下:
array([[False, False, True],
[True, False, False]], dtype=bool)
np.nan
是一个合适的浮点数,但None
是一个对象。因此你的数组具有对象类型。 - hpaulj