添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
沉稳的麻辣香锅  ·  NumPy ...·  昨天    · 
腼腆的桔子  ·  Pandas ...·  1 周前    · 
力能扛鼎的抽屉  ·  C# Pivot Table - ...·  3 周前    · 
仗义的夕阳  ·  Axisfault ...·  1 月前    · 
大方的西装  ·  pandas.Series.astype_P ...·  2 周前    · 
淡定的铅笔  ·  Asian Express - ...·  3 周前    · 
豪情万千的楼梯  ·  使用Python将data = ...·  4 月前    · 
爱旅游的小虾米  ·  SQL Developer ...·  1 年前    · 

weights : array_like, optional

An array of weights associated with the values in a . Each value in a contributes to the average according to its associated weight. The weights array can either be 1-D (in which case its length must be the size of a along the given axis) or of the same shape as a . If weights=None , then all data in a are assumed to have a weight equal to one.

returned : bool, optional

Default is False . If True , the tuple ( average , sum_of_weights ) is returned, otherwise only the average is returned. If weights=None , sum_of_weights is equivalent to the number of elements over which the average is taken.

Returns:

average, [sum_of_weights] : {array_type, double}

Return the average along the specified axis. When returned is True , return a tuple with the average as the first element and the sum of the weights as the second element. The return type is Float if a is of integer type, otherwise it is of the same type as a . sum_of_weights is of the same type as average .

Raises:

ZeroDivisionError :

When all weights along axis are zero. See numpy.ma.average for a version robust to this type of error.

TypeError :

When the length of 1D weights is not the same as the shape of a along axis.

>>> np . average ( data ) >>> np . average ( range ( 1 , 11 ), weights = range ( 10 , 0 , - 1 ))
>>> data = np.arange(6).reshape((3,2))
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.
    The Python Software Foundation is a non-profit corporation.  
    Please donate.
    Last updated on May 03, 2016.
    Found a bug?