summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-09-27 01:37:34 -0700
committerEric Wieser <wieser.eric@gmail.com>2017-09-27 01:39:04 -0700
commitf01d1a6a5c381a4406d92db2993bf01b8e849b8c (patch)
treebb09941ffbcae53d40009e182dd7846865606dd1 /numpy/ma
parent7666d14a5b5c2d94ddb064db83e85d8b8656c7d5 (diff)
downloadnumpy-f01d1a6a5c381a4406d92db2993bf01b8e849b8c.tar.gz
BUG: np.ma.trace gives the wrong result on ND arrays
Fixes #5560
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py2
-rw-r--r--numpy/ma/tests/test_core.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 1f70d78e0..67a813bf7 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -4819,7 +4819,7 @@ class MaskedArray(ndarray):
return result.astype(dtype)
else:
D = self.diagonal(offset=offset, axis1=axis1, axis2=axis2)
- return D.astype(dtype).filled(0).sum(axis=None, out=out)
+ return D.astype(dtype).filled(0).sum(axis=-1, out=out)
trace.__doc__ = ndarray.trace.__doc__
def dot(self, b, out=None, strict=False):
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index a99b56309..4dd18182c 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -3550,6 +3550,11 @@ class TestMaskedArrayMathMethods(object):
axis=0))
assert_equal(np.trace(mX), mX.trace())
+ # gh-5560
+ arr = np.arange(2*4*4).reshape(2,4,4)
+ m_arr = np.ma.masked_array(arr, False)
+ assert_equal(arr.trace(axis1=1, axis2=2), m_arr.trace(axis1=1, axis2=2))
+
def test_dot(self):
# Tests dot on MaskedArrays.
(x, X, XX, m, mx, mX, mXX, m2x, m2X, m2XX) = self.d