numpy.ma.average
- 
numpy.ma.average(a, axis=None, weights=None, returned=False)[source]
- 
Return the weighted average of array over the given axis. Parameters: a : array_like Data to be averaged. Masked entries are not taken into account in the computation. axis : int, optional Axis along which the average is computed. The default is to compute the average of the flattened array. weights : array_like, optional The importance that each element has in the computation of the average. The weights array can either be 1-D (in which case its length must be the size of aalong the given axis) or of the same shape asa. Ifweights=None, then all data inaare assumed to have a weight equal to one. Ifweightsis complex, the imaginary parts are ignored.returned : bool, optional Flag indicating whether a tuple (result, sum of weights)should be returned as output (True), or just the result (False). Default is False.Returns: average, [sum_of_weights] : (tuple of) scalar or MaskedArray 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 isnp.float64ifais of integer type and floats smaller thanfloat64, or the input data-type, otherwise. If returned,sum_of_weightsis alwaysfloat64.Examples>>> a = np.ma.array([1., 2., 3., 4.], mask=[False, False, True, True]) >>> np.ma.average(a, weights=[3, 1, 0, 0]) 1.25 >>> x = np.ma.arange(6.).reshape(3, 2) >>> print(x) [[ 0. 1.] [ 2. 3.] [ 4. 5.]] >>> avg, sumweights = np.ma.average(x, axis=0, weights=[1, 2, 3], ... returned=True) >>> print(avg) [2.66666666667 3.66666666667] 
    © 2008–2016 NumPy Developers
Licensed under the NumPy License.
    https://docs.scipy.org/doc/numpy-1.11.0/reference/generated/numpy.ma.average.html