[ Web Proxy ]
URL:
Viewing: https://numpy.org/doc/stable/reference/generated/numpy.matrix.sum.html [Back]  [Original]

numpy.matrix.sum — NumPy v2.5 Manual
Back to top
Search the docs ...:

numpy.matrix.sum#

method

matrix.sum(axis=None, dtype=None, out=None)[source]#

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 returned, a matrix object is returned instead.

Examples

Try it in your browser!
>>> x = np.matrix([[1, 2], [4, 3]])
>>> x.sum()
10
>>> x.sum(axis=1)
matrix([[3],
        [7]])
>>> x.sum(axis=1, dtype=np.float64)
matrix([[3.],
        [7.]])
>>> out = np.zeros((2, 1), dtype=np.float64)
>>> x.sum(axis=1, dtype=np.float64, out=np.asmatrix(out))
matrix([[3.],
        [7.]])

Web Proxy Viewer  |  New URL  |  Original Page