a guest May 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- from collections import deque
- class MovingAverage(object):
- def __init__(self, max_len=10):
- self.val = deque(maxlen=max_len)
- self.avg = 0
- self.maxlen = max_len
- def update(self, val):
- self.avg = sum(self.val) / self.maxlen
- # example:
- rm = MovingAverage()
- average = rm.avg # The first "max_len" values is not correct.
RAW Paste Data