MCPcopy Create free account
hub / github.com/numpy/numpy / sum

Method sum

numpy/matrixlib/defmatrix.py:288–320  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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...

Callers 2

test_sumMethod · 0.45
test_noaxisMethod · 0.45

Calls 1

_collapseMethod · 0.80

Tested by 2

test_sumMethod · 0.36
test_noaxisMethod · 0.36