How do I get a sequence of datetime values out of a sorted list, which all have a difference in time of at least x seconds? The sequence should always start at the first value of the list and include the last value, which had a difference bigger than x seconds to the second last value in the sequence.
Example with x = 1 seconds
Input_Arr = np.array([datetime(1981,1,1,0,0,0,40),
datetime(1981,1,1,0,0,0,80),
datetime(1981,1,1,0,0,1,20),
datetime(1981,1,1,0,0,1,50),
datetime(1981,1,1,0,0,2,00),
datetime(1981,1,1,0,0,2,70),
datetime(1981,1,1,0,0,3,10),
datetime(1981,1,1,0,0,3,40),
datetime(1981,1,1,0,0,4,20),
datetime(1981,1,1,0,0,5,00)])
Output_Arr: np.array([datetime(1981,1,1,0,0,0,40),
datetime(1981,1,1,0,0,1,50),
datetime(1981,1,1,0,0,2,70),
datetime(1981,1,1,0,0,4,20),
I think a combination of the following two approaches will be the solution, but I can't get the code correct. here here
The following works, but is not very clean and also not fast for bigger arrays.
Output_Arr = list()
time_delta = 1
for id, value in enumerate(Input_Arr):
if id == 0:
Output_Arr.append(value)
else:
if Output_Arr[-1] + timedelta(seconds=time_delta) < value:
Output_Arr.append(value)