def trim_structure(struct, filtering="<STR_LIT>", n=<NUM_LIT:2>):
X, Y, Z = (struct[:, i] for i in range(<NUM_LIT:3>))<EOL>if filtering == "<STR_LIT>":<EOL><INDENT>R = (np.std(X)**<NUM_LIT:2> + np.std(Y)**<NUM_LIT:2> + np.std(Z)**<NUM_LIT:2>) * (n**<NUM_LIT:2>)<EOL>f = (X - np.mean(X))**<NUM_LIT:2> + (Y - np.mean(Y))**<NUM_LIT:2> + (Z - np.mean(Z))**<NUM_LIT:2> < R<EOL><DEDENT>if filtering == "<STR_LIT>":<EOL><INDENT>R = min(np.std(X), np.std(Y), np.std(Z)) * n<EOL>f = np.ones(len(X))<EOL>for C in (X, Y, Z):<EOL><INDENT>f *= np.abs(C - np.mean(C)) < R<EOL><DEDENT><DEDENT>if filtering == "<STR_LIT>":<EOL><INDENT>f = np.ones(len(X))<EOL>for C in (X, Y, Z):<EOL><INDENT>f *= np.abs(C - np.mean(C)<EOL>) < np.percentile(np.abs(C - np.mean(C)), n)<EOL><DEDENT><DEDENT>return np.array([X[f], Y[f], Z[f]])<EOL>
Remove outlier 'atoms' (aka bins) from a structure.