我有2个列表,它们包含2个时间序列的谷值出现,这些时间序列在时间上移位。问题是山谷寻找算法不一致,即它会为时间序列1找到3个山谷,而对于时间序列2则会找到4个山谷。结果如下:
x = [7, 14, 18, 22]
y = [0, 9, 15, 19, 23, 35]
我的目标是尝试智能地对齐两个列表,即匹配7与9,14与15等,并获得:
x = [7, 14, 18, 22]
y = [9, 15, 19, 23]
2个笔记
有一种聪明而快速的方法吗?会很感激一些指导。
我的方法到目前为止,如果我假设最大偏差为2:
# pass number 1
p1 = [y + 1 for y in y]
p2 = [y - 1 for y in y]
best_guess = []
for i in range(len(y)):
if p1[i] in x or p2[i] in x:
best_guess.append(y[i])
# pass number 2
p1 = [y + 2 for y in y]
p2 = [y - 2 for y in y]
for i in range(len(y)):
if p1[i] in x or p2[i] in x:
if y[i] not in best_guess:
best_guess.append(y[i])
# sort since always in increasing order
best_guess.sort()