diff options
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 7149b525b..697565251 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -717,6 +717,13 @@ def _median(a, axis=None, out=None, overwrite_input=False): else: axis = normalize_axis_index(axis, asorted.ndim) + if asorted.shape[axis] == 0: + # for empty axis integer indices fail so use slicing to get same result + # as median (which is mean of empty slice = nan) + indexer = [slice(None)] * asorted.ndim + indexer[axis] = slice(0, 0) + return np.ma.mean(asorted[indexer], axis=axis, out=out) + if asorted.ndim == 1: counts = count(asorted) idx, odd = divmod(count(asorted), 2) |