nanvar

Contents

nanvar#

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

Compute the variance along the specified axis, while ignoring NaNs.

Returns the variance of the array elements, a measure of the spread of a distribution. NaN values are treated as missing. The resulting unit is the square of the input unit.

Parameters:
  • x (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Array containing numbers whose variance is desired. If x 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 non-NaN elements. By default ddof is zero.

  • keepdims (bool) – If True, the axes which are reduced are left in the result as dimensions with size one.

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

Returns:

variance – The variance of the non-NaN elements. 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
>>> import jax.numpy as jnp
>>> q = u.math.array([1.0, jnp.nan, 3.0]) * u.meter
>>> u.math.nanvar(q)  # unit becomes meter ** 2