kernels.weighted_average

kernels.weighted_average(arr, weights, *, validate=True)

Return the NaN-aware weighted average along the stack axis.

Parameters

arr : (ndarray, shape(N, *spatial))

Image stack. Accepted dtypes are uint8, uint16, int16, int32, float32, and float64. Integer inputs are promoted to the package’s floating workspace when validate is True. Inputs with more than 3 dimensions are flattened internally; output shapes match the trailing spatial dimensions of the input.

weights : (ndarray, shape(N))

Per-plane weights. The weighted sum skips non-finite pixels, so the effective denominator is the sum of weights for finite values at each output pixel.

validate : bool = True

If True, check dimensionality and normalize dtype/contiguity before entering the Rust kernel. If False, callers must provide inputs that satisfy the compiled kernel assumptions.

Returns

weighted_average : (ndarray, shape(*spatial))

Per-pixel weighted average. Pixels with no finite weighted samples return NaN.