This is documentation for an old release of NumPy (version 1.17.0). Read this page in the documentation of the latest stable release (version > 1.17).
numpy.matrix.sum¶
method
-
matrix.sum(self, axis=None, dtype=None, out=None)[source]¶ Returns the sum of the matrix elements, along the given axis.
Refer to
numpy.sumfor full documentation.See also
Notes
This is the same as
ndarray.sum, except that where anndarraywould be returned, amatrixobject is returned instead.Examples
>>> x = np.matrix([[1, 2], [4, 3]]) >>> x.sum() 10 >>> x.sum(axis=1) matrix([[3], [7]]) >>> x.sum(axis=1, dtype='float') matrix([[3.], [7.]]) >>> out = np.zeros((2, 1), dtype='float') >>> x.sum(axis=1, dtype='float', out=np.asmatrix(out)) matrix([[3.], [7.]])
