numojo.routines.math.sums¶
Summation routines for NuMojo (numojo.routines.math.sums).
Provides sum reductions along axes for NDArrays and Matrices, covering both flattened and axis-aware workflows.
Functions¶
sum¶
Overload 1¶
Returns sum of all items in the array.
Example:
> print(A)
[[ 0.1315377950668335 0.458650141954422 0.21895918250083923 ]
[ 0.67886471748352051 0.93469291925430298 0.51941639184951782 ]
[ 0.034572109580039978 0.52970021963119507 0.007698186207562685 ]]
2-D array Shape: [3, 3] DType: float32
> print(nm.sum(A))
3.5140917301177979
Parameters:
dtype(DType)
Args:
A(NDArray): NDArray.
Returns:
Scalar
Raises
Overload 2¶
Returns sums of array elements over a given axis.
Example:
Parameters:
dtype(DType)
Args:
A(NDArray): NDArray.axis(Int): The axis along which the sum is performed.
Returns:
NDArray
Raises
Error: If the axis is out of bound.
Error: If the number of dimensions is 1.
Overload 3¶
Sum up all items in the Matrix.
Example:
Parameters:
dtype(DType)
Args:
A(Matrix): Matrix.
Returns:
Scalar
Overload 4¶
Sum up the items in a Matrix along the axis.
Example:
from numojo import Matrix
var A = Matrix.rand(shape=(100, 100))
print(mat.sum(A, axis=0))
print(mat.sum(A, axis=1))
Parameters:
dtype(DType)
Args:
A(Matrix): Matrix.axis(Int): 0 or 1.
Returns:
Matrix
Raises
cumsum¶
Overload 1¶
Returns cumsum of all items of an array. The array is flattened before cumsum.
Parameters:
dtype(DType): The element type.
Args:
A(NDArray): NDArray.
Returns:
NDArray
Raises
Overload 2¶
Returns cumsum of array by axis.
Parameters:
dtype(DType): The element type.
Args:
A(NDArray): NDArray.axis(Int)[var]: Axis.
Returns:
NDArray
Raises
Overload 3¶
Cumsum of flattened matrix.
Example:
Parameters:
dtype(DType)
Args:
A(Matrix): Matrix.
Returns:
Matrix
Raises
Overload 4¶
Cumsum of Matrix along the axis.
Example:
from numojo import Matrix
var A = Matrix.rand(shape=(100, 100))
print(mat.cumsum(A, axis=0))
print(mat.cumsum(A, axis=1))
Parameters:
dtype(DType)
Args:
A(Matrix): Matrix.axis(Int): 0 or 1.
Returns:
Matrix
Raises