Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Author myrfy
- def moving_average(seq_in, window_size):
- sum = 0.0
- iter_ = iter(seq_in)
- buf_q = deque(maxlen=window_size)
- # build the init window
- for i in islice(iter_, window_size):
- buf_q.append(i)
- sum += i
- yield sum / len(buf_q)
- for i in iter_:
- sum -= buf_q.popleft()
- sum += i
- buf_q.append(i)
- yield sum / window_size
Add Comment
Please, Sign In to add comment