-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram10.py
More file actions
39 lines (29 loc) · 873 Bytes
/
program10.py
File metadata and controls
39 lines (29 loc) · 873 Bytes
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
#sum of a three dimensional numpy array along different axis
import numpy as np
seed_value = 1
np.random.seed(seed_value)
#random_matrix = np.random.rand(3,2,2)
random_matrix = np.random.randint(1, 10, size=(3,2,2))
#random_matrix = np.random.normal(loc=10, scale=3, size=(3,2,2))
print(random_matrix)
#sum all
sum_all = np.sum(random_matrix)
print(sum_all)
#sum along axis=0
sum_axis_0 = np.sum(random_matrix, axis=0)
print(sum_axis_0)
#sum along axis=1
sum_axis_1 = np.sum(random_matrix, axis=1)
print(sum_axis_1)
#sum along axis=2
sum_axis_2 = np.sum(random_matrix, axis=2)
print(sum_axis_2)
#sum along axis=(0,1)
sum_axis_01 = np.sum(random_matrix, axis=(0,1))
print(sum_axis_01)
#sum along axis=(0,2)
sum_axis_02 = np.sum(random_matrix, axis=(0,2))
print(sum_axis_02)
#sum along axis=(1,2)
sum_axis_12 = np.sum(random_matrix, axis=(1,2))
print(sum_axis_12)