402 | def sum(self, axis=None, dtype=None, out=None): |
403 | """ |
404 | Returns the sum of the matrix elements, along the given axis. |
405 | |
406 | Refer to `numpy.sum` for full documentation. |
407 | |
408 | See Also |
409 | -------- |
410 | numpy.sum |
411 | |
412 | Notes |
413 | ----- |
414 | This is the same as `ndarray.sum`, except that where an `ndarray` would |
415 | be returned, a `matrix` object is returned instead. |
416 | |
417 | Examples |
418 | -------- |
419 | >>> x = np.matrix([[1, 2], [4, 3]]) |
420 | >>> x.sum() |
421 | 10 |
422 | >>> x.sum(axis=1) |
423 | matrix([[3], |
424 | [7]]) |
425 | >>> x.sum(axis=1, dtype='float') |
426 | matrix([[ 3.], |
427 | [ 7.]]) |
428 | >>> out = np.zeros((1, 2), dtype='float') |
429 | >>> x.sum(axis=1, dtype='float', out=out) |
430 | matrix([[ 3.], |
431 | [ 7.]]) |
432 | |
433 | """ |
434 | return N.ndarray.sum(self, axis, dtype, out)._align(axis) |