a = np.array([[1, 2], [3, 4],[5, 6]])
print('-------------------')
print(np.sum(a))
print(a.sum())
print(a.sum(0))
print(np.sum(a,axis=0))
print(np.sum(a,axis=1))
print('-------------------')
print(np.mean(a))
print(a.mean())
print(a.mean(0))
print(np.mean(a, axis=0))
print(np.mean(a, axis=1))
print('-------------------')
print(np.std(a))
print(a.std())
print(a.std(1))
print(np.std(a, axis=0))
print(np.std(a, axis=1))
output:
-------------------
21
21
[ 9 12]
[ 9 12]
[ 3 7 11]
-------------------
3.5
3.5
[ 3. 4.]
[ 3. 4.]
[ 1.5 3.5 5.5]
-------------------
1.70782512766
1.70782512766
[ 0.5 0.5 0.5]
[ 1.63299316 1.63299316]
[ 0.5 0.5 0.5]
[Finished in 0.1s]
ps: axis 0 means do operator in each column individual. (first dimension.)
print(np.sum(a,axis=0))
[1,2]
[3,4]
[5,6]
=[1+3+5 , 2+4+6]= [9,12]
axis 1 means to operator second dimension.
print(np.sum(a,axis=1))
=[1+2,3+4,5+6]=[3,7,11]
---------------------
a = np.array([[1, 3,3, 4, 5, 6],[1, 3,3, 4, 5, 6]])
b = np.array([[1, 2,3, 4, 5, 6],[1, 1,1, 1, 1, 1]])
print(a)
print(np.mean(b, axis=0))
print(a-np.mean(b, axis=0))
[[1 3 3 4 5 6]
[1 3 3 4 5 6]]
[ 1. 1.5 2. 2.5 3. 3.5]
[[ 0. 1.5 1. 1.5 2. 2.5]
[ 0. 1.5 1. 1.5 2. 2.5]]
[Finished in 0.1s
沒有留言:
張貼留言