IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo function

mean

def mean[dtype: DType](src: Span[Scalar[dtype]]) -> Scalar[dtype]

Computes the mean value of the elements in a buffer.

Parameters:

  • ​dtype (DType): The dtype of the input.

Args:

Returns:

Scalar[dtype]: The mean value of the elements in the given buffer.

Raises:

If the operation fails.

def mean[dtype: DType, InputFn1DType: def[dtype_: DType, width: Int](idx: Int) -> SIMD[dtype_, width] & RegisterPassable & ImplicitlyCopyable](length: Int, input_fn_1d: InputFn1DType) -> Scalar[dtype]

Computes the arithmetic mean of values generated by a function.

Parameters:

  • ​dtype (DType): The data type of the elements.
  • ​InputFn1DType (def[dtype_: DType, width: Int](idx: Int) -> SIMD[dtype_, width] & RegisterPassable & ImplicitlyCopyable): The type of input_fn_1d (inferred).

Args:

  • ​length (Int): The number of elements to average.
  • ​input_fn_1d (InputFn1DType): A function that generates SIMD values at each index.

Returns:

Scalar[dtype]: The mean value. For integral types, uses integer division.

Raises:

To comply with how generators are used in this module.

Was this page helpful?