例1
mu = np.mean(features,axis=0)
features为M×N, 那么mu为(N,)或记1×N
例2
X_input = np.concatenate((features,intercept_feature),axis=1)
features为M×N,那么X_input为M ×(N+1)
例3
>>> a = np.array([[1, 2], [3, 4]])
>>> np.mean(a)
2.5
>>> np.mean(a, axis=0)
array([ 2., 3.])
>>> np.mean(a, axis=1)
array([ 1.5, 3.5])
例4
A = np.arange(8).reshape((2,2,2))
A:
array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
mu0 = np.mean(A,axis=0)
array([[2., 3.],
[4., 5.]])
mu1 = np.mean(A,axis=1)
array([[1., 2.],
[5., 6.]])
mu2= np.mean(A,axis=2)
array([[0.5, 2.5],
[4.5, 6.5]])
B=np.arange(50).reshape((2,5,5))
B:
array([[[ 0, 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]]])
B[0]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
C=np.arange(50).reshape((5,5,2))
C:
array([[[ 0, 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]]])
例5
A = np.arange(8).reshape((2,2,2))
A:
array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
filter_kernel_flipped=np.rot90(A, 1, (1,2))
filter_kernel_flipped:
array([[[1, 3],
[0, 2]],
[[5, 7],
[4, 6]]])
此例np.rot90()函数为axis1和axis2确定的平面内旋转一次。