diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2019-08-26 14:36:13 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2019-08-26 14:36:13 -0400 |
commit | ad49532a21cc007d4a1f0ba42f2a25db013c6505 (patch) | |
tree | 7426d0ec83d3157197839c0986b68caf93fb070a /numpy/lib/function_base.py | |
parent | dc089026b4ad0d2d9ea992c7f1b9b5e716dd82cd (diff) | |
download | numpy-ad49532a21cc007d4a1f0ba42f2a25db013c6505.tar.gz |
DOC: lib: Add more explanation of the weighted average calculation.
Also removed the incorrect comment from the docstring of `numpy.ma.average`
about the imaginary part of `weights` being ignored.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 9d380e67d..21532838b 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -316,14 +316,17 @@ def average(a, axis=None, weights=None, returned=False): 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. + weight equal to one. The 1-D calculation is:: + + avg = sum(a * weights) / sum(weights) + + The only constraint on `weights` is that `sum(weights)` must not be 0. 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 ------- retval, [sum_of_weights] : array_type or double |