Basic Reductions
These functions reduce an array along one or more axes, returning either a scalar (when all axes are reduced) or anNDArray with fewer dimensions.
ReductionOpts
The reductionssum, prod, amax/max, amin/min, all, and any accept an optional 4th argument opts: ReductionOpts for masked, seeded, or dtype-controlled reductions.
sum
Compute the sum of array elements over the given axis.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
prod
Compute the product of array elements over the given axis.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
mean
Compute the arithmetic mean along the specified axis.Integer inputs are automatically converted to
float64 for the result, matching NumPy behavior.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
std
Compute the standard deviation along the specified axis.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
variance
Compute the variance along the specified axis.var is a reserved word in JavaScript. This function is exported as both variance and var_ (or accessed via the var alias if your bundler supports it). Use variance to avoid conflicts.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
amin
Return the minimum of an array or minimum along an axis.Also exported as
min. Use amin to avoid shadowing Math.min.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
amax
Return the maximum of an array or maximum along an axis.Also exported as
max. Use amax to avoid shadowing Math.max.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
median
Compute the median along the specified axis.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
average
Compute the weighted average along the specified axis.
Returns:
number when reducing all axes, NDArray when reducing along specific axes. When returned=true, a tuple [avg, sum_of_weights] instead.
ptp
Peak to peak (maximum - minimum) value along an axis.
Returns:
number when reducing all axes, NDArray when reducing along specific axes.
all
Test whether all array elements along a given axis evaluate totrue.
Returns:
boolean when reducing all axes, NDArray (with boolean values) when reducing along specific axes.
any
Test whether any array element along a given axis evaluates totrue.
Returns:
boolean when reducing all axes, NDArray (with boolean values) when reducing along specific axes.