Trait dfdx::tensor_ops::MeanTo
source · pub trait MeanTo: HasErr + HasShape {
// Required method
fn try_mean<Dst: Shape, Ax: Axes>(
self
) -> Result<Self::WithShape<Dst>, Self::Err>
where Self::Shape: HasAxes<Ax> + ReduceShapeTo<Dst, Ax>;
// Provided method
fn mean<Dst: Shape, Ax: Axes>(self) -> Self::WithShape<Dst>
where Self::Shape: HasAxes<Ax> + ReduceShapeTo<Dst, Ax> { ... }
}
Expand description
Reduction along multiple axes using mean
.
Required Methods§
Provided Methods§
sourcefn mean<Dst: Shape, Ax: Axes>(self) -> Self::WithShape<Dst>where
Self::Shape: HasAxes<Ax> + ReduceShapeTo<Dst, Ax>,
fn mean<Dst: Shape, Ax: Axes>(self) -> Self::WithShape<Dst>where Self::Shape: HasAxes<Ax> + ReduceShapeTo<Dst, Ax>,
Mean reduction. Pytorch equivalent: t.mean(Axes)
Example:
let t = dev.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]);
let r = t.mean::<Rank0, _>(); // or `mean::<_, Axes2<0, 1>>()`
assert_eq!(r.array(), 3.5);
Reducing 1 axis:
let t = dev.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]);
let r = t.mean::<Rank1<2>, _>(); // or `mean::<_, Axis<1>>()`
assert_eq!(r.array(), [2.0, 5.0]);