x = np.empty([2], dtype=object)
> array([None, None], dtype=object)
x[0] = 'a'
> array(['a', None], dtype=object)
我想从这个对象中获取布尔数组[False, True]
的ndarray类型ndarray
在对象类型为None
。的elementwise比较无与对象D型
不起作用的东西:x is None
,x.isfinite()
,x == None
,np.isnan(x)
。该数组可能在n
维度中,使循环迭代看起来不愉快。
另外,你应该尽力避免w用'dtype = object'数组进行操作。他们基本上是发育不良的Python列表。也许你可以尝试一个大小的字符串dtype? –
NumPy的也有[MaskedArrays(https://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html),他们可能不完全容易初步掌握。但特别是如果你有一些“无效”条目,这些比对象数组快得多。 – MSeifert