diff options
author | Patrick Simianer <patrick@lilt.com> | 2021-05-21 17:49:04 +0200 |
---|---|---|
committer | Patrick Simianer <patrick@lilt.com> | 2021-05-21 17:49:04 +0200 |
commit | 8b325ba5ab9c825ec9fde53b87f0b947b0317b6c (patch) | |
tree | 07cc562ceba4d08c0186014f1504fb48a84066b1 /moving-average | |
parent | 53954eb5d4211c708f8b097247a5056a89026711 (diff) | |
parent | 6b72035db4a17dd9675cac4cd7adc17f8b1998e2 (diff) |
merge
Diffstat (limited to 'moving-average')
-rw-r--r-- | moving-average | 22 |
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() |