var¶
- tripy.var(input: Tensor, dim: int | Sequence[int] | None = None, keepdim: bool = False, correction: int = 1) Tensor [source]¶
Returns a new tensor containing the variance of the elements of the input tensor along the specified dimension.
The variance along a dimension is defined as:
\(\sigma^2 = \Large \frac{1}{max(0, N - \text{correction})} \large \sum_{i=1}^N (x_i - \bar{x})^2\)
where \(N\) is the length of the dimension, \(x_i\) is the \(i^{th}\) element along the dimension, and \(\bar{x}\) is the mean.
- Parameters:
input (Tensor) – [dtype=T1] The input tensor.
dim (int | Sequence[int] | None) – The dimension or dimensions along which to reduce. If this is not provided, all dimensions are reduced.
keepdim (bool) – Whether to retain reduced dimensions in the output. If this is False, reduced dimensions will be squeezed.
correction (int) – Defaults to Bessel’s correction.
- Returns:
[dtype=T1] variance of the input tensor
- Return type:
Example
1input = tp.reshape(tp.arange(6, dtype=tp.float32), (2, 3)) 2output = tp.var(input, dim=1, keepdim=True)
>>> input tensor( [[0.0000, 1.0000, 2.0000], [3.0000, 4.0000, 5.0000]], dtype=float32, loc=gpu:0, shape=(2, 3)) >>> output tensor( [[1.0000], [1.0000]], dtype=float32, loc=gpu:0, shape=(2, 1))