var

Contents

var#

class saiunit.math.var(a, axis=None, dtype=None, ddof=0, keepdims=False, *, where=None, **kwargs)#

Compute the variance along the specified axis.

Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis. The resulting unit is the square of the input unit.

Parameters:
  • a (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Array containing numbers whose variance is desired. If a is not an array, a conversion is attempted.

  • axis (int | Sequence[int] | None) – Axis or axes along which the variance is computed. The default is to compute the variance of the flattened array.

  • dtype (Any | None) – Type to use in computing the variance. For arrays of integer type the default is float64; for arrays of float types it is the same as the array type.

  • ddof (int) – “Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is zero.

  • keepdims (bool) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • where (Array | ndarray | bool | number | bool | int | float | complex | None) – Elements to include in the variance.

Returns:

variance – If the input has a unit, the result is a Quantity whose unit is the square of the input unit.

Return type:

saiunit.Quantity | Array

Examples

>>> import saiunit as u
>>> q = u.math.array([1.0, 2.0, 3.0]) * u.meter
>>> u.math.var(q)  # unit becomes meter ** 2