在python中使用mean函數的方法
mean():mean函數中作用是求取均值。
mean函數使用方法:
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.]])