MCPcopy Create free account
hub / github.com/numpy/numpy / nanvar

Function nanvar

numpy/lib/nanfunctions.py:1618–1770  ·  view source on GitHub ↗

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. The variance is computed for the flattened array by default, otherwise over the specified axis. For all-NaN slices or sli

(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue,
           *, where=np._NoValue)

Source from the content-addressed store, hash-verified

1616
1617@array_function_dispatch(_nanvar_dispatcher)
1618def nanvar(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue,
1619 *, where=np._NoValue):
1620 """
1621 Compute the variance along the specified axis, while ignoring NaNs.
1622
1623 Returns the variance of the array elements, a measure of the spread of
1624 a distribution. The variance is computed for the flattened array by
1625 default, otherwise over the specified axis.
1626
1627 For all-NaN slices or slices with zero degrees of freedom, NaN is
1628 returned and a `RuntimeWarning` is raised.
1629
1630 .. versionadded:: 1.8.0
1631
1632 Parameters
1633 ----------
1634 a : array_like
1635 Array containing numbers whose variance is desired. If `a` is not an
1636 array, a conversion is attempted.
1637 axis : {int, tuple of int, None}, optional
1638 Axis or axes along which the variance is computed. The default is to compute
1639 the variance of the flattened array.
1640 dtype : data-type, optional
1641 Type to use in computing the variance. For arrays of integer type
1642 the default is `float64`; for arrays of float types it is the same as
1643 the array type.
1644 out : ndarray, optional
1645 Alternate output array in which to place the result. It must have
1646 the same shape as the expected output, but the type is cast if
1647 necessary.
1648 ddof : int, optional
1649 "Delta Degrees of Freedom": the divisor used in the calculation is
1650 ``N - ddof``, where ``N`` represents the number of non-NaN
1651 elements. By default `ddof` is zero.
1652 keepdims : bool, optional
1653 If this is set to True, the axes which are reduced are left
1654 in the result as dimensions with size one. With this option,
1655 the result will broadcast correctly against the original `a`.
1656 where : array_like of bool, optional
1657 Elements to include in the variance. See `~numpy.ufunc.reduce` for
1658 details.
1659
1660 .. versionadded:: 1.22.0
1661
1662 Returns
1663 -------
1664 variance : ndarray, see dtype parameter above
1665 If `out` is None, return a new array containing the variance,
1666 otherwise return a reference to the output array. If ddof is >= the
1667 number of non-NaN elements in a slice or the slice contains only
1668 NaNs, then the result for that slice is NaN.
1669
1670 See Also
1671 --------
1672 std : Standard deviation
1673 mean : Average
1674 var : Variance while not ignoring NaNs
1675 nanstd, nanmean

Callers 1

nanstdFunction · 0.85

Calls 10

_replace_nanFunction · 0.85
_divide_by_countFunction · 0.85
_copytoFunction · 0.85
ndimMethod · 0.80
warnMethod · 0.80
varMethod · 0.45
dtypeMethod · 0.45
sumMethod · 0.45
squeezeMethod · 0.45
anyMethod · 0.45

Tested by

no test coverage detected