今天查看以前写的文章时, 发现有个地方理解不了, 就是 np.mean(a) 跟 a.mean() 的区别是什么, 于是就查阅了相关资料:

  • 官方doc:

a.mean()

Docstring:
a.mean(axis=None, dtype=None, out=None, keepdims=False)Returns the average of the array elements along given axis.Refer to `numpy.mean` for full documentation.See Also
--------
numpy.mean : equivalent function
Type:      builtin_function_or_method

np.mean(a)

Signature: np.mean(a, axis=None, dtype=None, out=None, keepdims=<no value>)
Docstring:
Compute the arithmetic mean along the specified axis.Returns the average of the array elements.  The average is taken over
the flattened array by default, otherwise over the specified axis.
`float64` intermediate and return values are used for integer inputs.Parameters
----------
a : array_likeArray containing numbers whose mean is desired. If `a` is not anarray, a conversion is attempted.
axis : None or int or tuple of ints, optionalAxis or axes along which the means are computed. The default is tocompute the mean of the flattened array... versionadded:: 1.7.0If this is a tuple of ints, a mean is performed over multiple axes,instead of a single axis or all the axes as before.
dtype : data-type, optionalType to use in computing the mean.  For integer inputs, the defaultis `float64`; for floating point inputs, it is the same as theinput dtype.
out : ndarray, optionalAlternate output array in which to place the result.  The defaultis ``None``; if provided, it must have the same shape as theexpected output, but the type will be cast if necessary.See `doc.ufuncs` for details.keepdims : bool, optionalIf this is set to True, the axes which are reduced are leftin the result as dimensions with size one. With this option,the result will broadcast correctly against the input array.If the default value is passed, then `keepdims` will not bepassed through to the `mean` method of sub-classes of`ndarray`, however any non-default value will be.  If thesub-class' method does not implement `keepdims` anyexceptions will be raised.Returns
-------
m : ndarray, see dtype parameter aboveIf `out=None`, returns a new array containing the mean values,otherwise a reference to the output array is returned.See Also
--------
average : Weighted average
std, var, nanmean, nanstd, nanvarNotes
-----
The arithmetic mean is the sum of the elements along the axis divided
by the number of elements.Note that for floating-point input, the mean is computed using the
same precision the input has.  Depending on the input data, this can
cause the results to be inaccurate, especially for `float32` (see
example below).  Specifying a higher-precision accumulator using the
`dtype` keyword can alleviate this issue.By default, `float16` results are computed using `float32` intermediates
for extra precision.Examples
--------
>>> a = np.array([[1, 2], [3, 4]])
>>> np.mean(a)
2.5
>>> np.mean(a, axis=0)
array([ 2.,  3.])
>>> np.mean(a, axis=1)
array([ 1.5,  3.5])In single precision, `mean` can be inaccurate:>>> a = np.zeros((2, 512*512), dtype=np.float32)
>>> a[0, :] = 1.0
>>> a[1, :] = 0.1
>>> np.mean(a)
0.54999924Computing the mean in float64 is more accurate:>>> np.mean(a, dtype=np.float64)
0.55000000074505806
File:      c:\users\huawei\appdata\local\programs\python\python36\lib\site-packages\numpy\core\fromnumeric.py
Type:      function
  • 总的来说, doc中所描述的是指 a.mean() 是 np.mean(a) 的简单版, 使用方法基本是相同的, 唯一的不同就是前者是numpy数组对象的方法, 后者作为numpy的函数使用.
  • 函数的作用就是: 返回数组元素沿给定轴的算数平均值。(算术平均值是沿坐标轴上的元素的和除以元素的个数。)
  • 沿坐标轴是什么意思, 参考:

参考文章1: python numpy.mean() axis参数使用方法【sum(axis=)是求和,mean(axis=)是求平均值】
https://blog.csdn.net/Dontla/article/details/96466644

参考文章2: python 如何理解 numpy 数组操作中的 axis 参数?
https://blog.csdn.net/Dontla/article/details/99751690

python numpy 中 np.mean(a) 跟 a.mean() 的区别相关推荐

  1. python Numpy 中的矩阵向量乘法(np.multiply()、np.dot()、np.matmul() 和 星号(*)、@)

    python Numpy 中的矩阵向量乘法 总结 1. 对于 np.array 对象 1.1 元素乘法 用 a*b 或 np.multiply(a,b) 1.2 矩阵乘法 用 np.dot(a,b) ...

  2. python 三维数组,numpy中np.shape的理解

    python 三维数组,numpy中np.shape的应用 直接贴图对于shape函数一般表示输出数组的形状,对于二维数组就是输出行与列,对于三维数组,shape[0]表示三维数组中包含多少个二维数组 ...

  3. python列表和数组区别java_浅谈numpy中np.array()与np.asarray的区别以及.tolist

    array和asarray都可以将结构数据转化为ndarray,但是主要区别就是当数据源是ndarray时,array仍然会copy出一个副本,占用新的内存,但asarray不会. 1.输入为列表时 ...

  4. python求向量函数的雅可比矩阵_在python Numpy中求向量和矩阵的范数实例

    np.linalg.norm(求范数):linalg=linear(线性)+algebra(代数),norm则表示范数. 函数参数 x_norm=np.linalg.norm(x, ord=None, ...

  5. python二维元素向量_详解python Numpy中求向量和矩阵的范数

    在python Numpy中求向量和矩阵的范数实例 np.linalg.norm(求范数):linalg=linear(线性)+algebra(代数),norm则表示范数. 函数参数 x_norm=n ...

  6. python3 nonzero_浅谈python numpy中nonzero()的用法

    nonzero函数返回非零元素的目录. 返回值为元组, 两个值分别为两个维度, 包含了相应维度上非零元素的目录值. import numpy as np A = np.mat([[0,1,2,3,4, ...

  7. 【numpy】numpy中np.nonzero()的用法

    nonzero(a) 返回数组a中非零元素的索引值数组. 只有a中非零元素才会有索引值,那些零值元素没有索引值: 返回的索引值数组是一个2维tuple数组,该tuple数组中包含一维的array数组. ...

  8. Numpy中np.mashgri() 函数介绍及2种应用场景

    @[toc](Numpy中np.mashgri() 函数介绍及2种应用场景 文章目录:) 近期在好几个地方都看到meshgrid的使用,虽然之前也注意到meshgrid的用法. 但总觉得印象不深刻,不 ...

  9. numpy 中np.max--求序列的最大值和np.maximum--X和Y逐位进行比较,选择最大值

    1.np.max(a, axis=None, out=None, keepdims=False) 求序列的最值 最少接受一个参数 axis默认为axis=0即列向,如果axis=1即横向 ex: &g ...

最新文章

  1. 024:模版查找路径配置
  2. 怎么用python统计字数_使用Python 统计高频字数的方法
  3. 【php】(转载)分享一个好用的php违禁词 处理类
  4. ubuntu14中 memcached安装与使用
  5. 您的空间不支持PHP,空间不支持fsockopen函数解决办法
  6. onlyoffice 20并发限制处理
  7. 【ArcGIS风暴】ArcGIS创建栅格数据集色彩映射表案例--以GlobeLand30土地覆盖数据为例
  8. python确定指标权重_python 实现熵权法确定各指标的权重
  9. 古代汉语(王力版)笔记 通论8-9
  10. [软考]项目管理常用案例总结
  11. opengl导入obj模型
  12. Linux中jsoncpp的编译使用
  13. “地理-语言”大模型文心ERNIE-GeoL及应用
  14. mysql datesub interval_Mysql之INTERVAL与DATE_SUB与EXTRACT函数的使用
  15. c3 linearization详解
  16. 基于K-Means的银行客户数据集分析与处理
  17. python白名单验证是什么意思_luminati python+selenium使用方式(白名单和账号密码验证方式)...
  18. 区块链和公益怎么如何融合到一起
  19. SAT语法之指示代词知识点
  20. FCK编辑器(完整详解)

热门文章

  1. arcgis怎么压缩tif文件_地理工具学习--arcgis篇:单工具学习(1)
  2. 自定义添加删除行按钮
  3. SAP激活物料分类帐
  4. SAP中破解系统管理员密码
  5. 《他其实没那么喜欢你》经典台词(4)
  6. SAP创建新新用户新角色和个人配置的相关方法
  7. 应届毕业生突破909万,数据盘点哪行工资最高,有你心仪的吗?
  8. 如何利用python3创建数据表_python3创建表及表数据;
  9. java中map可以为空吗_Java: Map里面的键和值可以为空吗?
  10. linux vsftpd用法,Linux_LINUX系统下vsftpd 命令详解,FTP命令是Internet用户使用最频 - phpStudy...