Verified Commit ed771458 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Add data tool

parent fff54520
#!/usr/bin/env python3
import argparse
import numpy as np
import json
def generate(args):
"""Generate a new dataset"""
data = np.random.normal(0, 1, 10000).tolist()
with open(args.output, "w") as output:
json.dump(data, output)
def process(args):
"""Process an existing dataset"""
with open(args.input) as input:
data = json.load(input)
data_sum = sum(data)
with open(args.output, "w") as output:
print(f"The sum is: {data_sum}", file=output)
actions = {
"generate": generate,
"process": process
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("command", metavar="CMD", choices=actions,
help="Run a command")
parser.add_argument("--input", "-i", metavar="PATH",
help="File to read")
parser.add_argument("--output", "-o", metavar="PATH",
help="File to write")
args = parser.parse_args()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment