npstreams.var(arrays, axis=-1, ddof=0, weights=None, ignore_nan=False)

Total variance of a stream of arrays. Weights are also supported. This function consumes the input stream.

  • arrays (iterable of ndarrays) – Arrays to be combined. This iterable can also a generator.

  • axis (int, optional) – Reduction axis. Default is to combine the arrays in the stream as if they had been stacked along a new axis, then compute the variance along this new axis. If None, arrays are flattened. If axis is an int larger that the number of dimensions in the arrays of the stream, variance is computed along the new axis.

  • ddof (int, optional) – Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.

  • weights (iterable of ndarray, iterable of floats, or None, optional) – Iterable of weights associated with the values in each item of arrays. Each value in an element of arrays contributes to the variance according to its associated weight. The weights array can either be a float or an array of the same shape as any element of arrays. If weights=None, then all data in each element of arrays are assumed to have a weight equal to one.

  • ignore_nan (bool, optional) – If True, NaNs are set to zero weight. Default is propagation of NaNs.


var – Variance.

Return type


See also


streaming variance


variance calculation for dense arrays. Weights are not supported.



D. H. D. West, Updating the mean and variance estimates: an improved method. Communications of the ACM Vol. 22, Issue 9, pp. 532 - 535 (1979)