Return (var, mean) along dim in a single call.
Variance counterpart to std_mean. Useful inside
normalisation layers where the squared deviation is the quantity
actually wanted (e.g. BatchNorm / LayerNorm forward computes
(x - mean) / sqrt(var + eps)).
Parameters
inputTensorInput.
dimint, sequence of int, or NoneAxis or axes to reduce.
None (default) → full-tensor
reduction. A bool here is unbiased: var_mean(x, False).unbiasedboolTrue is correction=1, False correction=0. A
number in this place is the correction itself, as
var_mean(x, dim, 0) has always been read.keepdimboolRetain the reduced axes as size-1 dimensions. Default
False.correctionint or floatBessel correction, as
lucid.var takes it. Default 1
(unbiased sample variance).Returns
tuple of Tensor(var, mean).
Notes
correction and keepdim apply with dim=None too; they used
to be dropped there. A single element has no spread to divide by
, so var_mean(tensor([5.0])) is (nan, 5).
Examples
>>> import lucid
>>> lucid.var_mean(lucid.tensor([[1.0, 3.0], [2.0, 6.0]]), 1)
(tensor([2., 8.]), tensor([2., 4.]))See Also
std_mean—standard-deviation + mean variant.