import numpy as np
def zero_runs(a):
# Create an array that is 1 where a is 0, and pad each end with an extra 0.
iszero = np.concatenate(([0], np.equal(a, 0).view(np.int8), [0]))
absdiff = np.abs(np.diff(iszero))
# Runs start and end where absdiff is 1.
ranges = np.where(absdiff == 1)[0].reshape(-1, 2)
return ranges
numpy 找到连续的序列的标号
最新推荐文章于 2021-12-21 11:02:55 发布
本文详细介绍了如何使用numpy库在Python中查找和提取数组中连续序列的索引。通过示例代码,展示了如何识别并获取连续数值的开始和结束位置。
摘要由CSDN通过智能技术生成