[英]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.