我可以对numpy数组执行大量统计,但"median"会返回属性错误.当我做"dir(np)"时,我确实看到列出的中位数方法.
(newpy2) 7831c1c083a2:src scaldara$ python
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy as np
>>> print(np.version.version)
1.11.2
>>> a = np.array([1,2,3,4,5,6,7,8,9,10])
>>> print(a)
[ 1 2 3 4 5 6 7 8 9 10]
>>> print(a.min())
1
>>> print(a.max())
10
>>> print(a.mean())
5.5
>>> print(a.std())
2.87228132327
>>> print(a.median())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'median'
>>>
Run Code Online (Sandbox Code Playgroud)
bri*_*pck 12
虽然numpy.ndarray有mean,max,std等方法,它没有一个median方法.有关可用的所有方法的列表ndarray,请参阅numpy文档ndarray.
它可以作为一个函数使用数组作为参数:
>>> import numpy as np
>>> a = np.array([1,2,3,4,5,6,7,8,9,10])
>>> np.median(a)
5.5
Run Code Online (Sandbox Code Playgroud)
正如您将在文档中ndarray.mean看到的,ndarray.mean并且np.mean是"等效函数",所以这只是语义问题.