添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Optionally Scipy-accelerated routines (numpy.dual)
  • Mathematical functions with automatic domain (numpy.emath)
  • Floating point error handling
  • Discrete Fourier Transform (numpy.fft)
  • Financial functions
  • Functional programming
  • NumPy-specific help functions
  • Indexing routines
  • 线性代数(numpy.linalg)
  • Mathematical functions
  • Matrix library (numpy.matlib)
  • Miscellaneous routines
  • Padding Arrays
  • Polynomials
  • Random sampling (numpy.random)
  • Set routines
  • Sorting, searching, and counting
  • Statistics
  • numpy.amin
  • numpy.amax
  • numpy.nanmin
  • numpy.nanmax
  • numpy.ptp
  • numpy.percentile
  • numpy.nanpercentile
  • numpy.quantile
  • numpy.nanquantile
  • numpy.median
  • numpy.average
  • numpy.mean
  • numpy.std
  • numpy.var
  • numpy.nanmedian
  • numpy.nanmean
  • numpy.nanstd
  • numpy.nanvar
  • numpy.corrcoef
  • numpy.correlate
  • numpy.cov
  • numpy.histogram
  • numpy.histogram2d
  • numpy.histogramdd
  • numpy.bincount
  • numpy.histogram_bin_edges
  • numpy.digitize
  • Test Support (numpy.testing)
  • Window functions
  • Packaging (numpy.distutils)
  • NumPy Distutils - Users Guide
  • NumPy C-API
  • NumPy内部
  • NumPy和SWIG
  • 一个 array_like

    包含要求平均值的数据的数组。如果 a 不是数组,则尝试进行转换。

    无或整数或整数元组,可选

    要平均 a的一个 或多个轴。默认值axis = None将对输入数组的所有元素求平均值。如果轴为负,则从最后一个到第一个轴计数。

    1.7.0版中的新功能。

    如果axis是int的元组,则对元组中指定的所有轴而不是以前的单个轴或所有轴执行平均。

    权重 array_like,可选

    与所述值相关联的权重的阵列 一个 。中的每个值 一个 根据其相关联的重量有助于平均。权重数组可以是1-D(在这种情况下,其长度必须是沿给定轴的 a 的大小)或与 a 相同的形状。如果 weights = None ,则假定 a 中的所有数据的权重等于1。一维计算为:

    avg = sum(a * weights) / sum(weights)
    

    权重的唯一约束是sum(weights)不得为0。

    返回布尔值,可选

    默认值为False。如果为True,则返回元组(averagesum_of_weights),否则仅返回平均值。如果weights = Nonesum_of_weights等于求平均值的元素数。

    retval,[sum_of_weights] array_type或double

    返回沿指定轴的平均值。当返回的,返回与平均的元组作为第一元件和配重的作为第二元件的总和。sum_of_weightsretval具有相同的类型。结果dtype遵循一般模式。如果权重是无,结果D型将是的一个,或者float64 如果一个是整体的。否则,如果权重不是None且a是非整数,则结果类型将是能够表示aweights值的最低精度类型。如果一个碰巧是整数,以前的规则仍然适用,但结果dtype至少为float64

    ZeroDivisionError

    沿轴的所有权重均为零时。请参阅numpy.ma.average以获取对此类错误更强健的版本。

    TypeError

    当1D的长度权重是不一样的形状 >>> np.average(data) >>> np.average(np.arange(1, 11), weights=np.arange(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.
    
    >>> a = np.ones(5, dtype=np.float128)
    >>> w = np.ones(5, dtype=np.complex64)
    >>> avg = np.average(a, weights=w)
    >>> print(avg.dtype)
    complex256