I am trying to classify data with python by first establishing a threshold then classifying it if it is above the threshold for a certain period of time.
Example data: My value threshold is >4 and my series threshold is >2
[5,5,1,1,1,5,5,5,4,4,4,4,5,5,5,5,5]
Expected output: Note the first two values are zero because they do not meet the series threshold
[0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1]
So, I only want to classify the data as 1 when it meets both the series and value threshold.
Does anyone know the best way to attach this problem with python?
IIUC, you can use numpy
in the following fashion:
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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.