According to the results of the operation in the code, mainly by the following:
1. SUM (): The result of adding each element in an array
2. Axis corresponds to the addition of the dimensions.
Like what:
1, when the axis=0, to drink is the first dimension elements of the addition,
[[0,1,2,3],[4,5,6,7]] and [[1,2,3,4],[5,6,7,8]] corresponding elements are added [[0+4,1+2,2+3,3+4],[4+5,5+6,7+7,7+8]]=[[1,3,5,7],[9,11,14,16] ]
2, when the Axis=1, the corresponding is the second dimension element addition, this time retains the first dimension's structure (number of first dimension element),
The number of the first dimension element is 2. respectively is
[[0,1,2,3],[4,5,6,7]] and [[1,2,3,4],[5,6,7,8]]
Structure unchanged, continue to split down, can be
(1) [0,1,2,3] and [4,5,6,7], the corresponding elements are added, merged into an array, [4,6,8,10]
(2) [1,2,3,4] and [5,6,7,8], the corresponding elements are added, merged into an array, 6,8,10,12]
3, when axis=2, because the element is three-dimensional, this is the last dimension, the smallest unit of the array elements can be added.
[0+1+2+3,4+5+6+7],[[1+2+3+4],[5+6+7+8]]=[[6,22],[10,26]]
Python code:
Import NumPy as NP
data=np.array ([[[[[0,1,2,3],[4,5,6,7]],[[1,2,3,4],[5,6,7,8]]])
sum=data.sum ()
sum0= Data.sum (axis=0)
sum1=data.sum (Axis=1)
sum2=data.sum (axis=2)
print "sum:", sum
print "axis=0:", SUM0
print "Axis=1:", sum1
print "axis=2:", sum2
Results: