diff options
author | edschofield <edschofield@localhost> | 2006-02-17 20:05:50 +0000 |
---|---|---|
committer | edschofield <edschofield@localhost> | 2006-02-17 20:05:50 +0000 |
commit | 2035b20ff5cfc6779f4b1a186e596c072423dc60 (patch) | |
tree | c9c135a7648d2f7a30601a900930dc2bc536d8d5 /numpy/core/defmatrix.py | |
parent | 9c339c6b39025ce5acd33a9728fde1b0bd47c3d6 (diff) | |
download | numpy-2035b20ff5cfc6779f4b1a186e596c072423dc60.tar.gz |
Fixed orientation of matrix.sum(axis=1), added unit test
Diffstat (limited to 'numpy/core/defmatrix.py')
-rw-r--r-- | numpy/core/defmatrix.py | 11 |
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): |