The Python NumPy (axis = 0/1/2 ...) thorough understanding of the

https://blog.csdn.net/sky_kkk/article/details/79725646

 

DESCRIPTION numpy axis value in the
first axis of the Value will be described numpy: axis = 0 when the one-dimensional array, axis = 0,1 when the two-dimensional array, the higher dimension, the axis preferably larger the value, the array n when the dimension, axis = 0,1, ..., n . In order to facilitate understanding below, we look at this: in the array have numpy [] flag, the axis = 0 corresponds to the outermost [], axis = 1 corresponds to the second outer layer [], and so on, axis = n corresponding to the n-th layer [].
The following starting axis = 0, axis = 1 these first two examples, and understands the axis numpy usage.
axis = 0 indicates the outermost maximum block unit [] is made in the calculation between the blocks, while removing the outermost layer []:
A = np.array ([l, 2,3])   
a.sum (Axis = 0)
>>> 6
123
because only one [], so that this layer is directly in the maximum operational units do fast 1,2,3;
this should be done after the addition [6], but removed after the outermost layer of [], [] does not exist, it returns 6.
np.array = A ([[1,2], [3,4-]]) 
a.sum (Axis = 0)
>>> Array ([. 4,. 6])
123
has two [], the outermost layer of [ ] where the maximum block unit, respectively [1,2], [3,4], the two blocks do arithmetic units between the blocks, [1,2] + [3,4] = [4, 6];
this should be done after the addition is [[4, 6]], but after removal of the outermost layer of [], the original two [] into a layer [], it returns a value of [4, 6] .
np.array ([[[1,2], [3,4]], [[11,12], [13,14]]])
a.sum (Axis = 0)
>>> Array ([[12 is, 14], [16, 18 is]])
123
has three [], the outermost layer of [] in the unit blocks are maximum [[1,2 ], [3,4]], [[11,12], [13,14]], the two blocks do arithmetic units between the blocks, [[1,2], [3,4] ] + [[11,12], [13,14]] = [[12, 14], [16, 18]];
this should be done after adding [[[12, 14], [16, 18] after]], but removes the outermost [], the original three [] into two [], it returns a value of [[12 is, 14], [16, 18 is]];
Axis =. 1 showing the first two outer layers [] in the block unit to make the maximum operation between the blocks, while removing the second outer layer []:
a = np.array ([l, 2,3])   
a.sum (Axis. 1 = )
>>> a ValueError: 'Axis' iS OUT of bounds entry
123
because only one [], only one value of Axis, is of 0. The
a = np.array ([[1,2], [3,4-]] ) 
a.sum (Axis =. 1)
>>> Array ([. 3,. 7])
123
has two [], the second outer layer [] in the block having two maximum units (since the two second outer layers []), a first group is 1, 2, 3, 4 of the second group, respectively, these two blocks do arithmetic units between the blocks, the first set of results is 1 + 2 = 3, the second group results for the 3 + 4 = 7;
this should be done after the addition is [[3], [7]], Removing the second outer layer is ** [] ** after the original two [] into a layer [], it returns a value of [3,
np.array ([[[1,2], [3,4-]], [[11, 12], [13, 14 are]]])
a.sum (Axis =. 1)
>>> Array ([[. 4 , 6], [24, 26]])
123
has three [], the second outer layer [] in the block having two maximum units (since the two second outer layers []), a first group is [1 , 2], [3,4], second group [11], [13, 14], respectively, these two blocks do arithmetic units between the blocks, the first set of results is [1, 2] + [3,4] = [4, 6], is a second set of results [11] + [13,14] = [24, 26]
after addition should be done [[[4, 6 ]], [[24, 26]]], * but removing the second outer layer [] ** after the original three [] into two [], it returns a value of [[4, 6] , [24-, 26]]
axis = 3,4,5 this analysis also
understand these instructions, I believe you already have in-depth understanding of the axis, the future no longer have to be afraid of high-dimensional array of computing on the axis!

Guess you like

Origin www.cnblogs.com/cupleo/p/11330373.html