Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `sklearn.utils.sparsefuncs`.mean_variance_axis

sklearn.utils.sparsefuncs.mean_variance_axis(X, axis, weights=None, return_sum_weights=False)

  Compute mean and variance along an axis on a CSR or CSC matrix.

  Parameters:
    X sparse matrix of shape (n_samples, n_features)

      Input data. It can be of CSR or CSC format.

    axis{0, 1}

      Axis along which the axis should be computed.

    weights ndarray of shape (n_samples,) or (n_features,), default=None

      If axis is set to 0 shape is (n_samples,) or if axis is set to 1 shape is (n_features,). If it is set to None, then samples are equally weighted.

      New in version 0.24.

    return_sum_weights bool, default=False

      If True, returns the sum of weights seen for each feature if `axis=0` or each sample if `axis=1`.

      New in version 0.24.

  Returns:
    means ndarray of shape (n_features,), dtype=floating

      Feature-wise means.

    variances ndarray of shape (n_features,), dtype=floating

      Feature-wise variances.

    sum_weights ndarray of shape (n_features,), dtype=floating

      Returned if `return_sum_weights` is `True`.