{ } Raw JSON

bundles / numpy 2.4.4 / numpy / matrixlib / defmatrix / matrix / sum

function

numpy.matrixlib.defmatrix:matrix.sum

source: /numpy/matrixlib/defmatrix.py:295

Signature

def sum(self, axis = None, dtype = None, out = None)

Summary

Returns the sum of the matrix elements, along the given axis.

Extended Summary

Refer to numpy.sum for full documentation.

Notes

This is the same as ndarray.sum, except that where an ndarray would be returned, a matrix object is returned instead.

Examples

x = np.matrix([[1, 2], [4, 3]])
✓
x.sum()
✗
np.int64(10)
x.sum(axis=1)
x.sum(axis=1, dtype='float')
out = np.zeros((2, 1), dtype='float')
x.sum(axis=1, dtype='float', out=np.asmatrix(out))
✓
matrix([[3.],
        [7.]])

See also

numpy.sum

Aliases

  • numpy.matrix.sum