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/ma | |
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/ma')
-rw-r--r-- | numpy/ma/extras.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 639b3dd1f..de1aa3af8 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -549,8 +549,11 @@ 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. If `weights` is complex, the imaginary parts - are ignored. + 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 Flag indicating whether a tuple ``(result, sum of weights)`` should be returned as output (True), or just the result (False). |