diff options
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/ma/core.py | 3 | ||||
| -rw-r--r-- | numpy/ma/tests/test_core.py | 24 |
2 files changed, 24 insertions, 3 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 82e5e7155..e3c6bc611 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -5290,9 +5290,6 @@ class MaskedArray(ndarray): """ m = self.mean(axis, dtype) - if m is masked: - return m - if not axis: return self - m else: diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 15ed26470..2fd353d23 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -3815,6 +3815,30 @@ class TestMaskedArrayMathMethods: assert_equal(a.mean(), 2) assert_equal(a.anom(), [-1, 0, 1]) + def test_anom_shape(self): + a = masked_array([1, 2, 3]) + assert_equal(a.anom().shape, a.shape) + a.mask = True + assert_equal(a.anom().shape, a.shape) + assert_(np.ma.is_masked(a.anom())) + + def test_anom(self): + a = masked_array(np.arange(1, 7).reshape(2, 3)) + assert_almost_equal(a.anom(), + [[-2.5, -1.5, -0.5], [0.5, 1.5, 2.5]]) + assert_almost_equal(a.anom(axis=0), + [[-1.5, -1.5, -1.5], [1.5, 1.5, 1.5]]) + assert_almost_equal(a.anom(axis=1), + [[-1., 0., 1.], [-1., 0., 1.]]) + a.mask = [[0, 0, 1], [0, 1, 0]] + mval = -99 + assert_almost_equal(a.anom().filled(mval), + [[-2.25, -1.25, mval], [0.75, mval, 2.75]]) + assert_almost_equal(a.anom(axis=0).filled(mval), + [[-1.5, 0.0, mval], [1.5, mval, 0.0]]) + assert_almost_equal(a.anom(axis=1).filled(mval), + [[-0.5, 0.5, mval], [-1.0, mval, 1.0]]) + def test_trace(self): # Tests trace on MaskedArrays. (x, X, XX, m, mx, mX, mXX, m2x, m2X, m2XX) = self.d |
