Created
October 6, 2013 01:36
-
-
Save treeherder/6848256 to your computer and use it in GitHub Desktop.
average a stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
streaam = [] | |
P = 100 | |
def SMA(N): | |
stream.append(N) | |
if len(stream) > P: | |
# Only average the last P elements of the stream | |
del(stream[:1]) | |
elif len(stream) == 0: | |
average = 0 | |
else: | |
average = sum(stream.iteritems() / len(stream) | |
return average | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment