var¶
- var(x: array, /, *, axis: int | Tuple[int, ...] | None = None, correction: int | float = 0.0, keepdims: bool = False) array ¶
Calculates the variance of the input array
x
.- Parameters:
x (array) – input array. Should have a real-valued floating-point data type.
axis (Optional[Union[int, Tuple[int, ...]]]) – axis or axes along which variances must be computed. By default, the variance must be computed over the entire array. If a tuple of integers, variances must be computed over multiple axes. A valid axis must be an integer on the interval
[-N, N)
, whereN
is the number of axes inx
. If an axis is specified as a negative integer, the function must determine the axis along which to perform the operation by counting backward from the last axis (where-1
refers to the last axis). If provided an invalid axis, the function must raise an exception. Default:None
.correction (Union[int, float]) – degrees of freedom adjustment. Setting this parameter to a value other than
0
has the effect of adjusting the divisor during the calculation of the variance according toM-c
whereM
corresponds to the total number of elements over which the variance is computed andc
corresponds to the provided degrees of freedom adjustment. When computing the variance of a population, setting this parameter to0
is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample variance, setting this parameter to1
is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel’s correction). Default:0
.keepdims (bool) – if
True
, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.
- Returns:
out (array) – if the variance is computed over the entire array, a zero-dimensional array containing the variance; otherwise, a non-zero-dimensional array containing the variances. The returned array must have the same data type as
x
.
Notes
While this specification recommends that this function only accept input arrays having a real-valued floating-point data type, specification-compliant array libraries may choose to accept input arrays having an integer data type. While mixed data type promotion is implementation-defined, if the input array
x
has an integer data type, the returned array must have the default real-valued floating-point data type.
Special Cases
Let
M
equal the number of elements over which to compute the variance.If
M - correction
is less than or equal to0
, the variance must beNaN
.If
x_i
isNaN
, the variance must beNaN
(i.e.,NaN
values propagate).