def robust_mean_mixture(x):
    "Compute the mean via a mixture of two Gaussians\n\n    One Gaussian accounts for outliers, and one Gaussian accounts  for\n    the true distribution.  This cannot be computed analytically, so\n    it uses scipy's function optimization\n    "
    if (len(x) == 1):
        return x
    x = x.ravel()
    mu_bg = np.mean(x)
    sig_bg = (3 * np.std(x))
    likelihood = (lambda v: (- np.sum(np.log((norm.pdf(x, v[0], v[1]) + norm.pdf(x, mu_bg, sig_bg))))))
    v0 = np.array([0, 30])
    v_best = optimize.fmin(likelihood, v0, disp=False)
    return v_best[0]
Compute the mean via a mixture of two Gaussians

One Gaussian accounts for outliers, and one Gaussian accounts  for
the true distribution.  This cannot be computed analytically, so
it uses scipy's function optimization
def robust_mean_mixture(x):
    "Compute the mean via a mixture of two Gaussians\n\n    One Gaussian accounts for outliers, and one Gaussian accounts  for\n    the true distribution.  This cannot be computed analytically, so\n    it uses scipy's function optimization\n    "
    if (len(x) == 1):
        return x
    x = x.ravel()
    mu_bg = np.mean(x)
    sig_bg = (3 * np.std(x))
    likelihood = (lambda v: (- np.sum(np.log((norm.pdf(x, v[0], v[1]) + norm.pdf(x, mu_bg, sig_bg))))))
    v0 = np.array([0, 30])
    v_best = optimize.fmin(likelihood, v0, disp=False)
    return v_best[0]