-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathfu784.py
More file actions
37 lines (28 loc) · 1.03 KB
/
fu784.py
File metadata and controls
37 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import numpy as np
def afunc(array1, array2, mode="+", pow=2):
assert array1.shape == array2.shape, "size mismatch"
assert type(pow) == int, "pow should be type int"
if mode == "+":
result = array1 + array2
elif mode == "-":
result = array1 - array2
else:
raise ValueError(f"mode is either '+' or '-' but got {mode}")
result = result ** pow
return result
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="This is tutorial for argparse.")
# add your code here
parser.add_argument("mode", type=str, help="the calculation mode")
parser.add_argument("pow", type=int, help="the power number used in calculation")
parser.add_argument("--print_hello", action="store_true", help="print 'Hello'")
# add your code here
args = parser.parse_args()
print(args)
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
result = afunc(a, b, args.mode, args.pow)
print(result)
if args.print_hello:
print("Hello!")