diff options
author | Ivan Gonzalez <scratchmex@gmail.com> | 2021-12-02 16:49:13 -0600 |
---|---|---|
committer | Ivan Gonzalez <scratchmex@gmail.com> | 2021-12-02 16:56:17 -0600 |
commit | 114d91919a9a0e0a7432468c27c1f723287b55f3 (patch) | |
tree | c2c4a90ef1e122964ed51cfde683abcdcc944e1f /numpy/ma/extras.py | |
parent | 742f13f7ee6ff8ed56fc468c9ef57b3853141768 (diff) | |
download | numpy-114d91919a9a0e0a7432468c27c1f723287b55f3.tar.gz |
BUG: fix `ma.average` not working well with nan weights
If a weight is nan it behaves erratically. See the tests added.
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 38bf1f0e8..56da5a7e5 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -592,7 +592,7 @@ def average(a, axis=None, weights=None, returned=False): avg = a.mean(axis) scl = avg.dtype.type(a.count(axis)) else: - wgt = np.asanyarray(weights) + wgt = asarray(weights) if issubclass(a.dtype.type, (np.integer, np.bool_)): result_dtype = np.result_type(a.dtype, wgt.dtype, 'f8') @@ -618,6 +618,7 @@ def average(a, axis=None, weights=None, returned=False): if m is not nomask: wgt = wgt*(~a.mask) + wgt.mask |= a.mask scl = wgt.sum(axis=axis, dtype=result_dtype) avg = np.multiply(a, wgt, dtype=result_dtype).sum(axis)/scl |