-
Notifications
You must be signed in to change notification settings - Fork 0
/
mean_var_std.py
24 lines (17 loc) · 1004 Bytes
/
mean_var_std.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
def calculate(list):
if len(list) != 9:
raise ValueError("List must contain nine numbers.")
matrix = np.reshape(list, (3, 3))
calculations = {
'mean': [matrix.mean(axis=0).tolist(), matrix.mean(axis=1).tolist(), matrix.flatten().mean()],
'variance': [matrix.var(axis=0).tolist(), matrix.var(axis=1).tolist(), matrix.flatten().var()],
'standard deviation': [matrix.std(axis=0).tolist(), matrix.std(axis=1).tolist(), matrix.flatten().std()],
'max': [matrix.max(axis=0).tolist(), matrix.max(axis=1).tolist(), matrix.flatten().max()],
'min': [matrix.min(axis=0).tolist(), matrix.min(axis=1).tolist(), matrix.flatten().min()],
'sum': [matrix.sum(axis=0).tolist(), matrix.sum(axis=1).tolist(), matrix.sum().item()]
}
for key, value in calculations.items():
for i in range(len(value)):
value[i] = value[i].tolist() if isinstance(value[i], np.ndarray) else value[i]
return calculations