def polyFitIgnoringOutliers(<EOL>x, y, deg=<NUM_LIT:2>, niter=<NUM_LIT:3>, nstd=<NUM_LIT:2>, return_outliers=False):
if return_outliers:<EOL><INDENT>a = all_outliers = np.zeros_like(y, dtype=bool)<EOL><DEDENT>for i in range(niter):<EOL><INDENT>poly = np.polyfit(x, y, deg)<EOL>p = np.poly1d(poly)<EOL>if i == niter - <NUM_LIT:1>:<EOL><INDENT>break<EOL><DEDENT>y_fit = p(x)<EOL>dy = y - y_fit<EOL>std = (dy**<NUM_LIT:2>).mean()**<NUM_LIT:0.5><EOL>inliers = abs(dy) < nstd * std<EOL>if return_outliers:<EOL><INDENT>a[~inliers] = True<EOL><DEDENT>if inliers.sum() > deg + <NUM_LIT:1>:<EOL><INDENT>x = x[inliers]<EOL>y = y[inliers]<EOL>if return_outliers:<EOL><INDENT>a = a[inliers]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if return_outliers:<EOL><INDENT>return p, all_outliers<EOL><DEDENT>return p<EOL>
Returns:
        (np.poly1d): callable function of polynomial fit excluding all outliers
    Args:
        deg (int): degree of polynomial fit
        n_iter (int): do linear regression n times
                      successive removing
        nstd (float): exclude outliers, if their deviation
            is > [nstd] * standard deviation
        return_outliers (bool): also return outlier positions as 2. arg