(X, weights=None, compute_variance=False)
Compute min, max, #nans, mean and variance.

    Result is a tuple (min, max, mean, variance, #nans, #non-nans) or an
    array of shape (len(X), 6).

    The mean and the number of nans and non-nans are weighted.

    Computation of variance requires an additional pass and is not enabled
    by default. Zeros are filled in instead of variance.

    Parameters
    ----------
    X : array_like, 1 or 2 dimensions
        Input array.
    weights : array_like, optional
        Weights, array of the same length as `x`.
    compute_variance : bool, optional
        If set to True, the function also computes variance.

    Returns
    -------
    out : a 6-element tuple or an array of shape (len(x), 6)
        Computed (min, max, mean, variance or 0, #nans, #non-nans)

    Raises
    ------
    ValueError
        If the length of the weight vector does not match the length of the
        array
Compute min, max, #nans, mean and variance.
Compute min max #nans mean and variance .
def stats(X, weights=None, compute_variance=False):
    """
    Compute min, max, #nans, mean and variance.

    Result is a tuple (min, max, mean, variance, #nans, #non-nans) or an
    array of shape (len(X), 6).

    The mean and the number of nans and non-nans are weighted.

    Computation of variance requires an additional pass and is not enabled
    by default. Zeros are filled in instead of variance.

    Parameters
    ----------
    X : array_like, 1 or 2 dimensions
        Input array.
    weights : array_like, optional
        Weights, array of the same length as `x`.
    compute_variance : bool, optional
        If set to True, the function also computes variance.

    Returns
    -------
    out : a 6-element tuple or an array of shape (len(x), 6)
        Computed (min, max, mean, variance or 0, #nans, #non-nans)

    Raises
    ------
    ValueError
        If the length of the weight vector does not match the length of the
        array
    """
    is_numeric = np.issubdtype(X.dtype, np.number)
    is_sparse = sp.issparse(X)
    weighted = weights is not None and X.dtype != object

    def weighted_mean():
        if is_sparse:
            w_X = X.multiply(sp.csr_matrix(np.c_[weights] / sum(weights)))
            return np.asarray(w_X.sum(axis=0)).ravel()
        else:
            return bn.nansum(X * np.c_[weights] / sum(weights), axis=0)

    if X.size and is_numeric and not is_sparse:
        nans = np.isnan(X).sum(axis=0)
        return np.column_stack((
            np.nanmin(X, axis=0),
            np.nanmax(X, axis=0),
            nanmean(X, axis=0) if not weighted else weighted_mean(),
            nanvar(X, axis=0) if compute_variance else \
                np.zeros(X.shape[1] if X.ndim == 2 else 1),
            nans,
            X.shape[0] - nans))
    elif is_sparse and X.size:
        if compute_variance:
            raise NotImplementedError

        non_zero = np.bincount(X.nonzero()[1], minlength=X.shape[1])
        X = X.tocsc()
        return np.column_stack((
            nanmin(X, axis=0),
            nanmax(X, axis=0),
            nanmean(X, axis=0) if not weighted else weighted_mean(),
            np.zeros(X.shape[1]),      # variance not supported
            X.shape[0] - non_zero,
            non_zero))
    else:
        nans = (pandas.isnull(X).sum(axis=0) + (X == "").sum(axis=0)) \
            if X.size else np.zeros(X.shape[1])
        return np.column_stack((
            np.tile(np.inf, X.shape[1]),
            np.tile(-np.inf, X.shape[1]),
            np.zeros(X.shape[1]),
            np.zeros(X.shape[1]),
            nans,
            X.shape[0] - nans))
def stats ( X , weights = None , compute_variance = False ) : is_numeric = np . issubdtype ( X . dtype , np . number ) is_sparse = sp . issparse ( X ) weighted = weights is not None and X . dtype != object def weighted_mean ( ) : if is_sparse : w_X = X . multiply ( sp . csr_matrix ( np . c_ [ weights ] / sum ( weights ) ) ) return np . asarray ( w_X . sum ( axis = 0 ) ) . ravel ( ) else : return bn . nansum ( X * np . c_ [ weights ] / sum ( weights ) , axis = 0 ) if X . size and is_numeric and not is_sparse : nans = np . isnan ( X ) . sum ( axis = 0 ) return np . column_stack ( ( np . nanmin ( X , axis = 0 ) , np . nanmax ( X , axis = 0 ) , nanmean ( X , axis = 0 ) if not weighted else weighted_mean ( ) , nanvar ( X , axis = 0 ) if compute_variance else np . zeros ( X . shape [ 1 ] if X . ndim == 2 else 1 ) , nans , X . shape [ 0 ] - nans ) ) elif is_sparse and X . size : if compute_variance : raise NotImplementedError non_zero = np . bincount ( X . nonzero ( ) [ 1 ] , minlength = X . shape [ 1 ] ) X = X . tocsc ( ) return np . column_stack ( ( nanmin ( X , axis = 0 ) , nanmax ( X , axis = 0 ) , nanmean ( X , axis = 0 ) if not weighted else weighted_mean ( ) , np . zeros ( X . shape [ 1 ] ) , # variance not supported X . shape [ 0 ] - non_zero , non_zero ) ) else : nans = ( pandas . isnull ( X ) . sum ( axis = 0 ) + ( X == "" ) . sum ( axis = 0 ) ) if X . size else np . zeros ( X . shape [ 1 ] ) return np . column_stack ( ( np . tile ( np . inf , X . shape [ 1 ] ) , np . tile ( - np . inf , X . shape [ 1 ] ) , np . zeros ( X . shape [ 1 ] ) , np . zeros ( X . shape [ 1 ] ) , nans , X . shape [ 0 ] - nans ) )