def trim_dense(M, n_std=<NUM_LIT:3>, s_min=None, s_max=None):
M = np.array(M)<EOL>sparsity = M.sum(axis=<NUM_LIT:1>)<EOL>mean = np.mean(sparsity)<EOL>std = np.std(sparsity)<EOL>if s_min is None:<EOL><INDENT>s_min = mean - n_std * std<EOL><DEDENT>if s_max is None:<EOL><INDENT>s_max = mean + n_std * std<EOL><DEDENT>elif s_max == <NUM_LIT:0>:<EOL><INDENT>s_max = np.amax(M)<EOL><DEDENT>f = (sparsity > s_min) * (sparsity < s_max)<EOL>N = M[f][:, f]<EOL>return N<EOL>
By default, return a matrix stripped of component
    vectors whose sparsity (i.e. total contact count on a
    single column or row) deviates more than specified number
    of standard deviations from the mean. Boolean variables
    s_min and s_max act as absolute fixed values which override
    such behaviour when specified.