python mean()

对于矩阵:

from numpy import  *
a=mat([[2,2,2],[4,4,4]])
print(a.mean())      #所有元素的平均值
print(mean(a))       #所有元素的平均值
print(mean(a,0))     #压缩行,对各列求平均值
print(mean(a,1))     #压缩列,对各行求平均值

输出:<class 'numpy.matrixlib.defmatrix.matrix'>

3.0
3.0
[[3. 3. 3.]]
[[2.]
 [4.]]

 

 对于数组:

from numpy import  *
a=array([[2,2,2],[4,4,4]])
print(a.mean())      #所有元素的平均值
print(mean(a))       #所有元素的平均值
print(mean(a,0))     #压缩行,对各列求平均值
print(mean(a,1))     #压缩列,对各行求平均值

 输出:<class 'numpy.ndarray'>

3.0
3.0
[3. 3. 3.]
[2. 4.]

 

posted @ 2018-11-08 22:45  我的下铺刚田武  阅读(18651)  评论(0编辑  收藏  举报