I think there is a typo in wt_mean because if it's a weighted mean of x with weights w it should be sum(x * w) / sum(w)