Skip to main content

average

Function average 

Source
pub fn average<T, D>(
    a: &Array<T, D>,
    weights: Option<&Array<T, D>>,
    axis: Option<usize>,
) -> FerrayResult<Array<T, IxDyn>>
where T: Element + Float + Send + Sync, D: Dimension,
Expand description

Weighted average of array elements.

When weights is None, equivalent to mean. When Some(w), computes sum(a * w) / sum(w) along the given axis (or over all elements when axis=None). The weights array must have the same shape as a (the 1-D-along-axis broadcasting form supported by NumPy is intentionally omitted here — call broadcast yourself first if you need it).

Analogous to numpy.average.

§Errors

  • FerrayError::InvalidValue if the array is empty.
  • FerrayError::ShapeMismatch if weights.shape() != a.shape().
  • FerrayError::InvalidValue if the weight sum along an axis is zero.