原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.average.html
校对:(虚位以待)
numpy.
average
(a, axis=None, weights=None, returned=False)[source]沿指定轴计算加权平均值。
参数: | a:array_like
axis:int,可选
权重:array_like,可选
返回:bool,可选
|
---|---|
返回: | average,[sum_of_weights]:array_type或double
|
上升: | ZeroDivisionError
TypeError
|
例子
>>> data = range(1,5)
>>> data
[1, 2, 3, 4]
>>> np.average(data)
2.5
>>> np.average(range(1,11), weights=range(10,0,-1))
4.0
>>> data = np.arange(6).reshape((3,2))
>>> data
array([[0, 1],
[2, 3],
[4, 5]])
>>> np.average(data, axis=1, weights=[1./4, 3./4])
array([ 0.75, 2.75, 4.75])
>>> np.average(data, weights=[1./4, 3./4])
Traceback (most recent call last):
...
TypeError: Axis must be specified when shapes of a and weights differ.