-
Notifications
You must be signed in to change notification settings - Fork 0
/
mean_var_std.py
29 lines (24 loc) · 1.03 KB
/
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
25
26
27
28
29
import numpy as np
def calculate(numbers):
# Validate input
if len(numbers) != 9:
raise ValueError("List must contain nine numbers.")
# Convert list to 3x3 numpy array
arr = np.array(numbers).reshape(3, 3)
# Calculate mean, variance, standard deviation, max, min, sum
mean = [list(np.mean(arr, axis=0)), list(np.mean(arr, axis=1)), np.mean(arr)]
variance = [list(np.var(arr, axis=0)), list(np.var(arr, axis=1)), np.var(arr)]
std_dev = [list(np.std(arr, axis=0)), list(np.std(arr, axis=1)), np.std(arr)]
max_val = [list(np.max(arr, axis=0)), list(np.max(arr, axis=1)), np.max(arr)]
min_val = [list(np.min(arr, axis=0)), list(np.min(arr, axis=1)), np.min(arr)]
sum_val = [list(np.sum(arr, axis=0)), list(np.sum(arr, axis=1)), np.sum(arr)]
# Construct output dictionary
calculations = {
'mean': mean,
'variance': variance,
'standard deviation': std_dev,
'max': max_val,
'min': min_val,
'sum': sum_val
}
return calculations