The problem is that I want to reduce the amount of data for graphs and analysis. I use Python and Numpy. The data is unevenly selected, so there is an array of timestamps and an array of corresponding values. I want this to be at least a certain amount of time between data points. I have a simple solution written in Python where the indexes are found where there is at least one second between the samples:
import numpy as np
t = np.array([0, 0.1, 0.2, 0.3, 1.0, 2.0, 4.0, 4.1, 4.3, 5.0 ])
v = np.array([0, 0.0, 2.0, 2.0, 2.0, 4.0, 4.0, 5.0, 5.0, 5.0 ])
idx = [0]
last_t = t[0]
min_dif = 1.0
for i in range(1, len(t)):
if last_t + min_dif <= t[i]:
last_t = t[i]
idx.append(i)
If we look at the result:
--> print idx
[0, 4, 5, 6, 9]
--> print t[idx]
[ 0. 1. 2. 4. 5.]
The question is, how can this be done more efficiently, especially if the arrays are really long? Are there any built-in NumPy or SciPy methods that do something like this?
source
share