def max_variance_genes(data, nbins=<NUM_LIT:5>, frac=<NUM_LIT>):
<EOL>indices = []<EOL>if sparse.issparse(data):<EOL><INDENT>means, var = sparse_mean_var(data)<EOL><DEDENT>else:<EOL><INDENT>means = data.mean(<NUM_LIT:1>)<EOL>var = data.var(<NUM_LIT:1>)<EOL><DEDENT>mean_indices = means.argsort()<EOL>n_elements = int(data.shape[<NUM_LIT:0>]/nbins)<EOL>frac_elements = int(n_elements*frac)<EOL>for i in range(nbins):<EOL><INDENT>bin_i = mean_indices[i*n_elements : (i+<NUM_LIT:1>)*n_elements]<EOL>if i==nbins-<NUM_LIT:1>:<EOL><INDENT>bin_i = mean_indices[i*n_elements :]<EOL><DEDENT>var_i = var[bin_i]<EOL>var_sorted = var_i.argsort()<EOL>top_var_indices = var_sorted[len(bin_i) - frac_elements:]<EOL>ind = bin_i[top_var_indices]<EOL>ind = [index for index in ind if var[index]><NUM_LIT:0>]<EOL>indices.extend(ind)<EOL><DEDENT>return indices<EOL>
This function identifies the genes that have the max variance
across a number of bins sorted by mean.

Args:
    data (array): genes x cells
    nbins (int): number of bins to sort genes by mean expression level. Default: 10.
    frac (float): fraction of genes to return per bin - between 0 and 1. Default: 0.1

Returns:
    list of gene indices (list of ints)