Returns the sum of the matrix elements, along the given axis. Refer to `numpy.sum` for full documentation. See Also -------- numpy.sum Notes ----- This is the same as `ndarray.sum`, except that where an `ndarray` would be re
(self, axis=None, dtype=None, out=None)
| 286 | |
| 287 | # To preserve orientation of result... |
| 288 | def sum(self, axis=None, dtype=None, out=None): |
| 289 | """ |
| 290 | Returns the sum of the matrix elements, along the given axis. |
| 291 | |
| 292 | Refer to `numpy.sum` for full documentation. |
| 293 | |
| 294 | See Also |
| 295 | -------- |
| 296 | numpy.sum |
| 297 | |
| 298 | Notes |
| 299 | ----- |
| 300 | This is the same as `ndarray.sum`, except that where an `ndarray` would |
| 301 | be returned, a `matrix` object is returned instead. |
| 302 | |
| 303 | Examples |
| 304 | -------- |
| 305 | >>> x = np.matrix([[1, 2], [4, 3]]) |
| 306 | >>> x.sum() |
| 307 | 10 |
| 308 | >>> x.sum(axis=1) |
| 309 | matrix([[3], |
| 310 | [7]]) |
| 311 | >>> x.sum(axis=1, dtype='float') |
| 312 | matrix([[3.], |
| 313 | [7.]]) |
| 314 | >>> out = np.zeros((2, 1), dtype='float') |
| 315 | >>> x.sum(axis=1, dtype='float', out=np.asmatrix(out)) |
| 316 | matrix([[3.], |
| 317 | [7.]]) |
| 318 | |
| 319 | """ |
| 320 | return N.ndarray.sum(self, axis, dtype, out, keepdims=True)._collapse(axis) |
| 321 | |
| 322 | |
| 323 | # To update docstring from array to matrix... |