def filter_variance(matrix, top):
assert isinstance(matrix, ExpMatrix)<EOL>assert isinstance(top, (int, np.integer))<EOL>if top >= matrix.p:<EOL><INDENT>logger.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return matrix.copy()<EOL><DEDENT>var = np.var(matrix.X, axis=<NUM_LIT:1>, ddof=<NUM_LIT:1>)<EOL>total_var = np.sum(var)  <EOL>a = np.argsort(var)<EOL>a = a[::-<NUM_LIT:1>]<EOL>sel = np.zeros(matrix.p, dtype=np.bool_)<EOL>sel[a[:top]] = True<EOL>lost_p = matrix.p - top<EOL>lost_var = total_var - np.sum(var[sel])<EOL>logger.info('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>top, <NUM_LIT:100> * (lost_p / float(matrix.p)),<EOL><NUM_LIT:100> * (lost_var / total_var))<EOL>matrix = matrix.loc[sel]<EOL>return matrix<EOL>
Filter genes in an expression matrix by variance.

    Parameters
    ----------
    matrix: ExpMatrix
        The expression matrix.
    top: int
        The number of genes to retain.

    Returns
    -------
    ExpMatrix
        The filtered expression matrix.