Mojo function
mean
mean(src: NDBuffer[dtype, 1, origin]) -> Scalar[dtype]
Computes the mean value of the elements in a buffer.
Args:
- src (
NDBuffer): The buffer of elements for which the mean is computed.
Returns:
Scalar: The mean value of the elements in the given buffer.
Raises:
If the operation fails.
mean[reduce_axis: Int](src: NDBuffer[dtype, rank, origin, shape, strides, alignment2=alignment2, address_space=address_space, exclusive=exclusive], dst: NDBuffer[dtype, rank, origin, shape])
Computes the mean across reduce_axis of an NDBuffer.
Parameters:
- reduce_axis (
Int): The axis to reduce across.
Args:
Raises:
If the operation fails.
mean[dtype: DType, input_fn: fn[width: Int, rank: Int](IndexList[rank]) capturing -> SIMD[dtype, width], output_fn: fn[width: Int, rank: Int](IndexList[rank], SIMD[dtype, width]) capturing -> None, /, single_thread_blocking_override: Bool = False, target: StringSlice[StaticConstantOrigin] = "cpu"](input_shape: IndexList[size], reduce_dim: Int, output_shape: IndexList[size], context: DeviceContextPtr = DeviceContextPtr())
Computes the mean across the input and output shape.
This performs the mean computation on the domain specified by input_shape,
loading the inputs using the input_fn. The results' domain is
output_shape which are stored using the output_fn.
Parameters:
- dtype (
DType): The dtype of the input and output. - input_fn (
fn[width: Int, rank: Int](IndexList[rank]) capturing -> SIMD[dtype, width]): The function to load the input. - output_fn (
fn[width: Int, rank: Int](IndexList[rank], SIMD[dtype, width]) capturing -> None): The function to store the output. - single_thread_blocking_override (
Bool): If True, then the operation is run synchronously using a single thread. - target (
StringSlice): The target to run on.
Args:
- input_shape (
IndexList): The input shape. - reduce_dim (
Int): The axis to perform the mean on. - output_shape (
IndexList): The output shape. - context (
DeviceContextPtr): The pointer to DeviceContext.
Raises:
If the operation fails.
mean[dtype: DType, input_fn_1d: fn[dtype_: DType, width: Int](idx: Int) capturing -> SIMD[dtype_, width]](length: Int) -> Scalar[dtype]
Computes the arithmetic mean of values generated by a function.
Parameters:
- dtype (
DType): The data type of the elements. - input_fn_1d (
fn[dtype_: DType, width: Int](idx: Int) capturing -> SIMD[dtype_, width]): A function that generates SIMD values at each index.
Args:
- length (
Int): The number of elements to average.
Returns:
Scalar: The mean value. For integral types, uses integer division.
Raises:
To comply with how generators are used in this module.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!