def robust_mean_iterated(x, sigma_cut=3):
    'Compute the robust mean iteratively\n\n    After computing the mean, points further than 3 sigma from the mean\n    are removed and the result is repeated until convergence.\n    '
    flag = np.ones(x.shape, dtype=bool)
    n_to_keep = x.size
    while True:
        xf = x[flag]
        mu = xf.mean()
        sig = xf.std()
        if (len(xf) == 1):
            break
        x_sig = abs(((x - mu) / sig))
        too_far = (x_sig > sigma_cut)
        flag[too_far] = False
        n_flag = flag.sum()
        if (n_flag == n_to_keep):
            break
        else:
            n_to_keep = n_flag
    return mu
Compute the robust mean iteratively

After computing the mean, points further than 3 sigma from the mean
are removed and the result is repeated until convergence.
def robust_mean_iterated(x, sigma_cut=3):
    'Compute the robust mean iteratively\n\n    After computing the mean, points further than 3 sigma from the mean\n    are removed and the result is repeated until convergence.\n    '
    flag = np.ones(x.shape, dtype=bool)
    n_to_keep = x.size
    while True:
        xf = x[flag]
        mu = xf.mean()
        sig = xf.std()
        if (len(xf) == 1):
            break
        x_sig = abs(((x - mu) / sig))
        too_far = (x_sig > sigma_cut)
        flag[too_far] = False
        n_flag = flag.sum()
        if (n_flag == n_to_keep):
            break
        else:
            n_to_keep = n_flag
    return mu