summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--moving-average22
1 files changed, 22 insertions, 0 deletions
diff --git a/moving-average b/moving-average
new file mode 100644
index 0000000..e32a777
--- /dev/null
+++ b/moving-average
@@ -0,0 +1,22 @@
+import numpy as np
+import optparse
+
+
+def main():
+ cmdlineParser = optparse.OptionParser(usage="")
+ (options, args) = cmdlineParser.parse_args()
+ path = args[0]
+ window = int(args[1])
+ half_window = window/2
+ f = open(path, "r")
+ numbers = []
+ for line in f.readlines():
+ numbers.append(float(line))
+
+ for i in range(len(numbers)):
+ min_id = max(0, i-window)
+ print(np.average(numbers[min_id:i+1]))
+
+
+if __name__ == "__main__":
+ main()