blosc2.sum#
- blosc2.sum(ndarr: NDArray | NDField | C2Array | LazyExpr, axis: int | tuple[int] | None = None, dtype: dtype = None, keepdims: bool = False, **kwargs: dict) ndarray | NDArray | int | float | complex | bool #
Return the sum of array elements over a given axis.
- Parameters:
ndarr¶ (NDArray or NDField or C2Array or LazyExpr) – The input array or expression.
axis¶ (int or tuple of ints, optional) – Axis or axes along which a sum is performed. By default, axis=None, sums all the elements of the input array. If axis is negative, it counts from the last to the first axis.
dtype¶ (np.dtype, optional) – The type of the returned array and of the accumulator in which the elements are summed. The dtype of
ndarr
is used by default unless it has an integer dtype of less precision than the default platform integer.keepdims¶ (bool, optional) – If set to True, the reduced axes are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
kwargs¶ (dict, optional) – Additional keyword arguments supported by the
empty()
constructor.
- Returns:
sum_along_axis – The sum of the elements along the axis.
- Return type:
np.ndarray or NDArray or scalar
References
Examples
>>> import numpy as np >>> import blosc2 >>> # Example array >>> array = np.array([[1, 2, 3], [4, 5, 6]]) >>> nd_array = blosc2.asarray(array) >>> # Sum all elements in the array (axis=None) >>> total_sum = blosc2.sum(nd_array) >>> print("Sum of all elements:", total_sum) 21 >>> # Sum along axis 0 (columns) >>> sum_axis_0 = blosc2.sum(nd_array, axis=0) >>> print("Sum along axis 0 (columns):", sum_axis_0) Sum along axis 0 (columns): [5 7 9]