diff options
author | Amit Aronovitch <aronovitch@gmail.com> | 2016-05-01 00:17:23 +0300 |
---|---|---|
committer | Amit Aronovitch <aronovitch@gmail.com> | 2016-05-22 00:04:21 +0300 |
commit | bb46a495ee5201fb94c14776f41181343e5b7fb2 (patch) | |
tree | 3cbeda16bb4ad9d397af1119c330c93063624470 /numpy/ma/extras.py | |
parent | 2423048255f74aeefc22f707fcccfb8d21723ce3 (diff) | |
download | numpy-bb46a495ee5201fb94c14776f41181343e5b7fb2.tar.gz |
BUG: ma.median of 1d array should return a scalar
Fixes #5969.
Performance fix #4760 had caused wrong shaped results in the 1D case.
This fix restores the original 1D behavior.
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index ea8f9e49a..2a44397d7 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -27,7 +27,7 @@ import warnings from . import core as ma from .core import ( - MaskedArray, MAError, add, array, asarray, concatenate, filled, + MaskedArray, MAError, add, array, asarray, concatenate, filled, count, getmask, getmaskarray, make_mask_descr, masked, masked_array, mask_or, nomask, ones, sort, zeros, getdata, get_masked_subclass, dot, mask_rowcols @@ -653,6 +653,10 @@ def _median(a, axis=None, out=None, overwrite_input=False): elif axis < 0: axis += a.ndim + if asorted.ndim == 1: + idx, odd = divmod(count(asorted), 2) + return asorted[idx - (not odd) : idx + 1].mean() + counts = asorted.shape[axis] - (asorted.mask).sum(axis=axis) h = counts // 2 # create indexing mesh grid for all but reduced axis |