MCPcopy Index your code
hub / github.com/numpy/numpy / sum

Method sum

numpy/matrixlib/defmatrix.py:293–325  ·  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

291
292 # To preserve orientation of result...
293 def sum(self, axis=None, dtype=None, out=None):
294 """
295 Returns the sum of the matrix elements, along the given axis.
296
297 Refer to `numpy.sum` for full documentation.
298
299 See Also
300 --------
301 numpy.sum
302
303 Notes
304 -----
305 This is the same as `ndarray.sum`, except that where an `ndarray` would
306 be returned, a `matrix` object is returned instead.
307
308 Examples
309 --------
310 >>> x = np.matrix([[1, 2], [4, 3]])
311 >>> x.sum()
312 10
313 >>> x.sum(axis=1)
314 matrix([[3],
315 [7]])
316 >>> x.sum(axis=1, dtype=np.float64)
317 matrix([[3.],
318 [7.]])
319 >>> out = np.zeros((2, 1), dtype=np.float64)
320 >>> x.sum(axis=1, dtype=np.float64, out=np.asmatrix(out))
321 matrix([[3.],
322 [7.]])
323
324 """
325 return N.ndarray.sum(self, axis, dtype, out, keepdims=True)._collapse(axis)
326
327 # To update docstring from array to matrix...
328 def squeeze(self, axis=None):

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