(x, axis=None, ddof=0)
return _apply_func(x, bn.nanvar, nanvar_sparse, axis=axis)
Equivalent of np.nanvar that supports sparse or dense matrices.
Equivalent of np.nanvar that supports sparse or dense matrices.
Equivalent of np . nanvar that supports sparse or dense matrices .
def nanvar(x, axis=None, ddof=0):
    """ Equivalent of np.nanvar that supports sparse or dense matrices. """
    def nanvar_sparse(x):
        n_vals = np.prod(x.shape) - np.sum(np.isnan(x.data))
        n_zeros = np.prod(x.shape) - len(x.data)
        avg = np.nansum(x.data) / n_vals
        return (np.nansum((x.data - avg) ** 2) + avg ** 2 * n_zeros) / (n_vals - ddof)

    return _apply_func(x, bn.nanvar, nanvar_sparse, axis=axis)
def nanvar ( x , axis = None , ddof = 0 ) : def nanvar_sparse ( x ) : n_vals = np . prod ( x . shape ) - np . sum ( np . isnan ( x . data ) ) n_zeros = np . prod ( x . shape ) - len ( x . data ) avg = np . nansum ( x . data ) / n_vals return ( np . nansum ( ( x . data - avg ) ** 2 ) + avg ** 2 * n_zeros ) / ( n_vals - ddof ) return _apply_func ( x , bn . nanvar , nanvar_sparse , axis = axis )