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.]

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM