我有一个很大的数据集(>;200k),我正在尝试用一个值替换零序。大于2个零的零序是一个伪影,应该通过将其设置为np.NAN公司. 你知道吗
我读过Searching a sequence in a NumPy array,但它不完全符合我的要求,因为我没有静态模式。你知道吗
np.array([0, 1.0, 0, 0, -6.0, 13.0, 0, 0, 0, 1.0, 16.0, 0, 0, 0, 0, 1.0, 1.0, 1.0, 1.0])
# should be converted to this
np.array([0, 1.0, 0, 0, -6.0, 13.0, NaN, NaN, NaN, 1.0, 16.0, NaN, NaN, NaN, NaN, 1.0, 1.0, 1.0, 1.0])
如果你需要更多的信息,请告诉我。 提前谢谢!你知道吗
谢谢你的回答,这是我的(不专业的)测试结果288240分
divakar took 0.016000ms to replace 87912 points
desiato took 0.076000ms to replace 87912 points
polarise took 0.102000ms to replace 87912 points
因为@Divakar的解是最短最快的,所以我接受他的解。你知道吗
您可以使用itertools包的groupby
这给了你
请注意,每个
int
都转换为float
。请看这里:NumPy or Pandas: Keeping array type as integer while having a NaN value下面是一个可用于列表的函数:
因为列表是在一个方向上遍历的,所以只有两个比较:
(0, 0, 0)
或(NaN, NaN, 0)
,因为在执行时用NaN
替换0
。你知道吗这基本上是一个^{} ,在闭合间隙上有一个阈值要求。这是一个基于它的实现-
有一种方法可以避免在处理边界元素时根据需要在早期方法中附加边界元素,这可能会使处理大型数据集时的成本有点高,如下所示-
相关问题 更多 >
编程相关推荐