summaryrefslogtreecommitdiff
path: root/numpy/core/defmatrix.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/defmatrix.py')
-rw-r--r--numpy/core/defmatrix.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/numpy/core/defmatrix.py b/numpy/core/defmatrix.py
index d506220a2..9234d2f53 100644
--- a/numpy/core/defmatrix.py
+++ b/numpy/core/defmatrix.py
@@ -188,6 +188,17 @@ class matrix(N.ndarray):
def __str__(self):
return str(self.__array__())
+ def sum(self, axis=None, dtype=None):
+ """Sum the matrix over the given axis. If the axis is None, sum
+ over all dimensions. This preserves the orientation of the
+ result as a row or column.
+ """
+ s = N.ndarray.sum(self, axis, dtype)
+ if axis==1:
+ return s.transpose()
+ else:
+ return s
+
# Needed becase tolist method expects a[i]
# to have dimension a.ndim-1
def tolist(self):