From dbf3fcb19ec710732531c268aeba7aa348e872f1 Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Wed, 6 Jan 2016 11:37:47 -0500 Subject: BUG trace is not subclass aware, such that np.trace(ma) != ma.trace(). --- numpy/core/fromnumeric.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'numpy/core/fromnumeric.py') diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 362c29cb8..a2937c5c5 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1367,7 +1367,11 @@ def trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None): (2, 3) """ - return asarray(a).trace(offset, axis1, axis2, dtype, out) + if isinstance(a, np.matrix): + # Get trace of matrix via an array to preserve backward compatibility. + return asarray(a).trace(offset, axis1, axis2, dtype, out) + else: + return asanyarray(a).trace(offset, axis1, axis2, dtype, out) def ravel(a, order='C'): -- cgit v1.2.1