滚动窗口迭代器还是滑动窗口迭代器?
def rolling_window(seq, window_size): it = iter(seq) win = [it.next() for cnt in xrange(window_size)] # First window yield win for e in it: # Subsequent windows win[:-1] = win[1:] win[-1] = e yield winif __name__=="__main__": for w in rolling_window(xrange(6), 3): print w"""Example output: [0, 1, 2] [1, 2, 3] [2, 3, 4] [3, 4, 5] """
翻过高山走不出你
慕容森
蝴蝶不菲
相关分类