Burn Core: burn::tensor::Tensor::mean_dim
The Tensor::mean_dim method aggregates tensor values along a selected dimension using the arithmetic mean. The parameter dim identifies the axis to reduce. The method is commonly used for feature normalization, batch statistics, channel reduction, and loss preparation.
The output preserves the tensor rank while reducing the selected dimension according to Burn tensor semantics. When used in differentiable code, the mean operation distributes gradient contribution evenly across the aggregated elements.
Parameters
| Parameter Name | Type | Description |
|---|---|---|
self |
Tensor<B, D> |
The tensor whose values are reduced by arithmetic mean. |
dim |
usize |
The dimension index along which the mean is computed. |
let device = B::Device::default();
let x = Tensor::<B, 2>::ones([4, 8], &device);
let mean = x.mean_dim(0);
println!("{mean}");
Example Output
{
"status": "success",
"operation": "mean_dim",
"input_shape": [4, 8],
"dimension": 0
}