diff options
author | Patrick Simianer <pks@pks.rocks> | 2020-08-02 09:46:42 +0200 |
---|---|---|
committer | Patrick Simianer <pks@pks.rocks> | 2020-08-02 09:46:42 +0200 |
commit | 74e20e00dfbffdcf117778049e47acd79e320110 (patch) | |
tree | 30d323a146c7292fedf8333293544278d44dab3a | |
parent | b76bedcec1750586b88536203090c22d97dd64e7 (diff) |
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() |