diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/extras.py | 3 | ||||
-rw-r--r-- | numpy/ma/tests/test_extras.py | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 0d5c73e7e..e4ff8ef2d 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -727,9 +727,8 @@ def _median(a, axis=None, out=None, overwrite_input=False): ind = np.meshgrid(*axes_grid, sparse=True, indexing='ij') # insert indices of low and high median - ind.insert(axis, h - 1) + ind.insert(axis, np.maximum(0, h - 1)) low = asorted[tuple(ind)] - low._sharedmask = False ind[axis] = h high = asorted[tuple(ind)] diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py index 27fac3d63..0a6de4eba 100644 --- a/numpy/ma/tests/test_extras.py +++ b/numpy/ma/tests/test_extras.py @@ -790,6 +790,15 @@ class TestMedian(TestCase): assert_equal(r, out) assert_(type(r) == MaskedArray) + def test_single_non_masked_value_on_axis(self): + data = [[1., 0.], + [0., 3.], + [0., 0.]] + masked_arr = np.ma.masked_equal(data, 0) + expected = [1., 3.] + assert_array_equal(np.ma.median(masked_arr, axis=0), + expected) + class TestCov(TestCase): |