sum
sum(
a,
axis=None,
*,
weights=None,
return_sum_weights=False,
return_unweighted_sum=False,
validate=True,
)Return the sum with NaN/inf propagation.
Parameters
a : array_like-
Input data. Supported numeric inputs are normalized to a contiguous kernel array when
validate=True. Computed reducers promote integer and bool inputs tofloat64; exact selection reducers keep integer and bool dtypes where the selected value can be returned exactly. Complex and object arrays are not supported. axis : None, 0, -1, or int = None-
Axis to reduce.
Nonereduces the whole array.0reduces strided reducing-axis slices into the remaining shape.-1andndim - 1reduce contiguous slices. Other axes raiseNotImplementedError. weights : None or array_like = None-
If provided, return
sum(a * weights)instead ofsum(a). Withaxis=None, weights must have the same shape asa. With an axis reduction, weights may either have the same shape asaor be 1-D with length equal to the reducing axis. return_sum_weights : bool = False-
If
Trueandweightsis provided, also return the sum of retained weights. return_unweighted_sum : bool = False-
If
Trueandweightsis provided, also return the unweighted sum of retainedavalues. validate : bool = True-
If
True, check dtype, dimensionality, contiguity, and axis validity before entering the Rust kernel. IfFalse, the caller must provide a contiguous supported kernel dtype (float32,float64, bool, or a NumPy integer dtype).validate=Falseskips dtype promotion: integer and bool arrays are reduced directly, while complex and object arrays remain unsupported.
Returns
out : float, ndarray, or tuple-
Reduction result.
axis=Nonereturns a Pythonfloat. Axis reductions return an array with the reduced axis removed. Withweightsand optional return flags, returns(weighted_sum, sum_weights),(weighted_sum, unweighted_sum), or(weighted_sum, sum_weights, unweighted_sum).
Notes
Plain reducers include every value, so NaN and inf propagate with IEEE / NumPy-like semantics. This is the fastest path for known-clean finite data.
Weighted sums compute sum(a * weights) in one pass. For nansum, weights attached to skipped values are skipped with them; optional sum_weights and unweighted sums use the same retained-value policy. Like return_mean for variance and standard deviation, these optional returns expose quantities already available in the fused kernel and avoid separate reductions at the call site.