mean() 函數定義:
numpy.mean(a, axis, dtype, out,keepdims )
mean()函數功能:求取均值
經常操作的參數為axis,以m * n矩陣舉例:
axis 不設置值,對 mn 個數求均值,返回一個實數
axis = 0:壓縮行,對各列求均值,返回 1 n 矩陣
axis = 1 :壓縮列,對各行求均值,返回 m *1 矩陣
舉例:
>>> import numpy as np
>>> num1 = np.array([[1,2,3],[2,3,4],[3,4,5],[4,5,6]])
>>> now2 = np.mat(num1)
>>> now2
matrix([[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
[4, 5, 6]])
>>> np.mean(now2) # 對所有元素求均值
3.5
>>> np.mean(now2,0) # 壓縮行,對各列求均值
matrix([[ 2.5, 3.5, 4.5]])
>>> np.mean(now2,1) # 壓縮列,對各行求均值
matrix([[ 2.],
[ 3.],
[ 4.],
[ 5.]])
參考:http://blog.csdn.net/taotiezhengfeng/article/details/72397282