-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmean_var_std.py
More file actions
52 lines (33 loc) · 1.31 KB
/
mean_var_std.py
File metadata and controls
52 lines (33 loc) · 1.31 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
mean_var_std.py
"""
import numpy as np
numbers_list = [0, 1, 2, 3, 4, 5, 6, 7, 8]
def calculate(numbers_list):
if len(numbers_list) != 9:
return "List must contain nine numbers."
matrix = np.array(numbers_list).reshape(3, 3)
print(matrix)
mean = list(np.mean(matrix, axis = 0)), list(np.mean(matrix, axis = 1)), np.mean(matrix)
mean = list(mean)
variance = list(np.var(matrix, axis = 0)), list(np.var(matrix, axis = 1)), np.var(matrix)
variance = list(variance)
std = list(np.std(matrix, axis = 0)), list(np.std(matrix, axis = 1)), np.std(matrix)
std = list(std)
max_n = list(np.max(matrix, axis = 0)), list(np.max(matrix, axis = 1)), np.max(matrix)
max_n = list(max_n)
min_n = list(np.min(matrix, axis = 0)), list(np.min(matrix, axis = 1)), np.min(matrix)
min_n = list(min_n)
sum_n = list(np.sum(matrix, axis = 0)), list(np.sum(matrix, axis = 1)), np.sum(matrix)
sum_n = list(sum_n)
calculations = {
"mean" : list(mean),
"variance" : list(variance),
"standard deviation" : list(std),
"max" : list(max_n),
"min" : list(min_n),
"sum" : list(sum_n)
}
return calculations