diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2013-06-15 11:22:05 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2013-06-15 12:12:39 -0400 |
commit | ace8ee7b4b81af7600c53e093e104ef53d54482c (patch) | |
tree | 255bce6e2356debff243af2b11a3cb70f04819db /numpy/ma/extras.py | |
parent | 4a7f2b7601ad1b82f0fd8c3df1e548e83215abcf (diff) | |
download | numpy-ace8ee7b4b81af7600c53e093e104ef53d54482c.tar.gz |
BUG: ma: ma.average didn't handle complex arrays correctly (issue gh-2684)
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 5a484ce9d..d14812093 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -455,7 +455,8 @@ 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. If `weights` is 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). @@ -515,7 +516,7 @@ def average(a, axis=None, weights=None, returned=False): if mask is nomask: if weights is None: d = ash[axis] * 1.0 - n = add.reduce(a._data, axis, dtype=float) + n = add.reduce(a._data, axis) else: w = filled(weights, 0.0) wsh = w.shape @@ -531,14 +532,14 @@ def average(a, axis=None, weights=None, returned=False): r = [None] * len(ash) r[axis] = slice(None, None, 1) w = eval ("w[" + repr(tuple(r)) + "] * ones(ash, float)") - n = add.reduce(a * w, axis, dtype=float) + n = add.reduce(a * w, axis) d = add.reduce(w, axis, dtype=float) del w, r else: raise ValueError('average: weights wrong shape.') else: if weights is None: - n = add.reduce(a, axis, dtype=float) + n = add.reduce(a, axis) d = umath.add.reduce((-mask), axis=axis, dtype=float) else: w = filled(weights, 0.0) @@ -547,7 +548,7 @@ def average(a, axis=None, weights=None, returned=False): wsh = (1,) if wsh == ash: w = array(w, dtype=float, mask=mask, copy=0) - n = add.reduce(a * w, axis, dtype=float) + n = add.reduce(a * w, axis) d = add.reduce(w, axis, dtype=float) elif wsh == (ash[axis],): ni = ash[axis] @@ -555,7 +556,7 @@ def average(a, axis=None, weights=None, returned=False): r[axis] = slice(None, None, 1) w = eval ("w[" + repr(tuple(r)) + \ "] * masked_array(ones(ash, float), mask)") - n = add.reduce(a * w, axis, dtype=float) + n = add.reduce(a * w, axis) d = add.reduce(w, axis, dtype=float) else: raise ValueError('average: weights wrong shape.') @@ -580,7 +581,6 @@ def average(a, axis=None, weights=None, returned=False): return result - def median(a, axis=None, out=None, overwrite_input=False): """ Compute the median along the specified axis. |