[英]Is there a way to classify data points with python above a value and series threshold (consecutive numbers above the threshold)?
我试图通过首先建立一个阈值然后在一段时间内高于阈值时对其进行分类来对 python 的数据进行分类。
示例数据:我的值阈值 >4,我的系列阈值 >2
[5,5,1,1,1,5,5,5,4,4,4,4,5,5,5,5,5]
预期 output:注意前两个值为零,因为它们不符合系列阈值
[0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1]
所以,我只想在数据同时满足系列和值阈值时将数据分类为 1。
有谁知道用 python 附加此问题的最佳方法?
IIUC,您可以按以下方式使用numpy
:
import numpy as np
a = np.array([5,5,1,1,1,5,5,5,4,4,4,4,5,5,5,5,5])
v_threshold = 4
s_threshold = 2
out = np.zeros_like(a)
out[s_threshold:] = a[s_threshold:] > v_threshold
#array([0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.