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

Function sum

numpy/_core/fromnumeric.py:2343–2466  ·  view source on GitHub ↗

Sum of array elements over a given axis. Parameters ---------- a : array_like Elements to sum. axis : None or int or tuple of ints, optional Axis or axes along which a sum is performed. The default, axis=None, will sum all of the elements of the input a

(a, axis=None, dtype=None, out=None, keepdims=np._NoValue,
        initial=np._NoValue, where=np._NoValue)

Source from the content-addressed store, hash-verified

2341
2342@array_function_dispatch(_sum_dispatcher)
2343def sum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue,
2344 initial=np._NoValue, where=np._NoValue):
2345 """
2346 Sum of array elements over a given axis.
2347
2348 Parameters
2349 ----------
2350 a : array_like
2351 Elements to sum.
2352 axis : None or int or tuple of ints, optional
2353 Axis or axes along which a sum is performed. The default,
2354 axis=None, will sum all of the elements of the input array. If
2355 axis is negative it counts from the last to the first axis. If
2356 axis is a tuple of ints, a sum is performed on all of the axes
2357 specified in the tuple instead of a single axis or all the axes as
2358 before.
2359 dtype : dtype, optional
2360 The type of the returned array and of the accumulator in which the
2361 elements are summed. The dtype of `a` is used by default unless `a`
2362 has an integer dtype of less precision than the default platform
2363 integer. In that case, if `a` is signed then the platform integer
2364 is used while if `a` is unsigned then an unsigned integer of the
2365 same precision as the platform integer is used.
2366 out : ndarray, optional
2367 Alternative output array in which to place the result. It must have
2368 the same shape as the expected output, but the type of the output
2369 values will be cast if necessary.
2370 keepdims : bool, optional
2371 If this is set to True, the axes which are reduced are left
2372 in the result as dimensions with size one. With this option,
2373 the result will broadcast correctly against the input array.
2374
2375 If the default value is passed, then `keepdims` will not be
2376 passed through to the `sum` method of sub-classes of
2377 `ndarray`, however any non-default value will be. If the
2378 sub-class' method does not implement `keepdims` any
2379 exceptions will be raised.
2380 initial : scalar, optional
2381 Starting value for the sum. See `~numpy.ufunc.reduce` for details.
2382 where : array_like of bool, optional
2383 Elements to include in the sum. See `~numpy.ufunc.reduce` for details.
2384
2385 Returns
2386 -------
2387 sum_along_axis : ndarray
2388 An array with the same shape as `a`, with the specified
2389 axis removed. If `a` is a 0-d array, or if `axis` is None, a scalar
2390 is returned. If an output array is specified, a reference to
2391 `out` is returned.
2392
2393 See Also
2394 --------
2395 ndarray.sum : Equivalent method.
2396 add: ``numpy.add.reduce`` equivalent function.
2397 cumsum : Cumulative sum of array elements.
2398 trapezoid : Integration of array values using composite trapezoidal rule.
2399
2400 mean, average

Callers 15

test_memmap_subclassMethod · 0.90
covFunction · 0.90
test_addsumprodMethod · 0.90
test_reduceMethod · 0.90
test_traceMethod · 0.90
testSumMethod · 0.85
test_advance_largeMethod · 0.85
test_advance_largeMethod · 0.85

Calls 1

_wrapreductionFunction · 0.85

Tested by 15

test_memmap_subclassMethod · 0.72
test_addsumprodMethod · 0.72
test_reduceMethod · 0.72
test_traceMethod · 0.72
testSumMethod · 0.68
test_advance_largeMethod · 0.68
test_advance_largeMethod · 0.68
test_edge_casesMethod · 0.68
test_diophantine_fuzzFunction · 0.68