sum
Calculates the sum of the input array x
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
input array of a numeric data type. |
required | |
axis
|
axis or axes along which sums are computed.
By default, the sum is computed over the entire array.
If a tuple of integers, sums must are computed over multiple axes. Default: |
None
|
|
dtype
|
data type of the returned array.
If
If the data type (either specified or resolved) differs from the data type of |
None
|
|
keepdims
|
If |
False
|
Returns:
Name | Type | Description |
---|---|---|
out |
array
|
if the sum was computed over the entire array, a zero-dimensional array containing the sum.
Otherwise, an array containing the sums.
The returned array has the data type as described by the |
Special Cases
Let N
equal the number of elements over which to compute the sum.
- If
N
is0
, the sum is0
(i.e., the empty sum).
Examples:
>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
>>> o = sparse.sum(a, axis=1)
>>> o.todense()
array([1, 2])
Source code in sparse/numba_backend/_common.py
2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 |
|