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

Function sum

numpy/core/fromnumeric.py:2178–2314  ·  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

2176
2177@array_function_dispatch(_sum_dispatcher)
2178def sum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue,
2179 initial=np._NoValue, where=np._NoValue):
2180 """
2181 Sum of array elements over a given axis.
2182
2183 Parameters
2184 ----------
2185 a : array_like
2186 Elements to sum.
2187 axis : None or int or tuple of ints, optional
2188 Axis or axes along which a sum is performed. The default,
2189 axis=None, will sum all of the elements of the input array. If
2190 axis is negative it counts from the last to the first axis.
2191
2192 .. versionadded:: 1.7.0
2193
2194 If axis is a tuple of ints, a sum is performed on all of the axes
2195 specified in the tuple instead of a single axis or all the axes as
2196 before.
2197 dtype : dtype, optional
2198 The type of the returned array and of the accumulator in which the
2199 elements are summed. The dtype of `a` is used by default unless `a`
2200 has an integer dtype of less precision than the default platform
2201 integer. In that case, if `a` is signed then the platform integer
2202 is used while if `a` is unsigned then an unsigned integer of the
2203 same precision as the platform integer is used.
2204 out : ndarray, optional
2205 Alternative output array in which to place the result. It must have
2206 the same shape as the expected output, but the type of the output
2207 values will be cast if necessary.
2208 keepdims : bool, optional
2209 If this is set to True, the axes which are reduced are left
2210 in the result as dimensions with size one. With this option,
2211 the result will broadcast correctly against the input array.
2212
2213 If the default value is passed, then `keepdims` will not be
2214 passed through to the `sum` method of sub-classes of
2215 `ndarray`, however any non-default value will be. If the
2216 sub-class' method does not implement `keepdims` any
2217 exceptions will be raised.
2218 initial : scalar, optional
2219 Starting value for the sum. See `~numpy.ufunc.reduce` for details.
2220
2221 .. versionadded:: 1.15.0
2222
2223 where : array_like of bool, optional
2224 Elements to include in the sum. See `~numpy.ufunc.reduce` for details.
2225
2226 .. versionadded:: 1.17.0
2227
2228 Returns
2229 -------
2230 sum_along_axis : ndarray
2231 An array with the same shape as `a`, with the specified
2232 axis removed. If `a` is a 0-d array, or if `axis` is None, a scalar
2233 is returned. If an output array is specified, a reference to
2234 `out` is returned.
2235

Callers 15

test_memmap_subclassMethod · 0.90
covFunction · 0.90
test_addsumprodMethod · 0.90
test_reduceMethod · 0.90
test_traceMethod · 0.90
_concatenate_shapesFunction · 0.70
einsum_pathFunction · 0.70
testSumMethod · 0.50
test_advange_largeMethod · 0.50
test_advange_largeMethod · 0.50

Calls 2

_wrapreductionFunction · 0.85
warnMethod · 0.80

Tested by 15

test_memmap_subclassMethod · 0.72
test_addsumprodMethod · 0.72
test_reduceMethod · 0.72
test_traceMethod · 0.72
testSumMethod · 0.40
test_advange_largeMethod · 0.40
test_advange_largeMethod · 0.40
test_edge_casesMethod · 0.40
test_diophantine_fuzzFunction · 0.40