Guest User

Untitled

a guest
Oct 17th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. # Author myrfy
  2. def moving_average(seq_in, window_size):
  3. sum = 0.0
  4. iter_ = iter(seq_in)
  5. buf_q = deque(maxlen=window_size)
  6. # build the init window
  7. for i in islice(iter_, window_size):
  8. buf_q.append(i)
  9. sum += i
  10. yield sum / len(buf_q)
  11.  
  12. for i in iter_:
  13. sum -= buf_q.popleft()
  14. sum += i
  15. buf_q.append(i)
  16. yield sum / window_size
Add Comment
Please, Sign In to add comment