zhhy236400

对于矩阵:

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

 

分类:

技术点:

相关文章:

  • 2021-05-17
  • 2021-04-07
  • 2022-12-23
  • 2021-12-21
  • 2021-09-19
  • 2021-10-29
  • 2021-09-25
  • 2022-01-03
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2021-09-27
  • 2021-08-07
  • 2022-12-23
  • 2021-11-01
  • 2021-06-29
相关资源
相似解决方案