mean() 函数定义:
numpy.mean(a, axis, dtype, out,keepdims )

mean()函数功能:求取均值
经常操作的参数为axis,以m * n矩阵举例:

  • axis 不设置值,对 m*n 个数求均值,返回一个实数
  • axis = 0:压缩行,对各列求均值,返回 1* n 矩阵
  • axis =1 :压缩列,对各行求均值,返回 m *1 矩阵

例子:
数组的操作:

>>> a = np.array([[1, 2], [3, 4]])
>>> a
array([[1, 2],
[3, 4]])
>>> np.mean(a)
2.5
>>> np.mean(a, axis=0) # axis=0,计算每一列的均值
array([ 2., 3.])
>>> np.mean(a, axis=1) # 计算每一行的均值 
array([ 1.5, 3.5])
>>> 

 



相关文章:

  • 2022-12-23
  • 2022-01-21
  • 2021-07-20
  • 2021-04-16
  • 2021-06-14
  • 2021-11-01
  • 2022-01-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-22
  • 2021-11-07
相关资源
相似解决方案