My try at code golfing.
The problem of finding the minimum value of ∑W_i*|X-X_i| reduces to finding the weighted median of a list of x[i] with weights <
Just a comment about your code : I really hope I will not have to maintain it, unless you also wrote all the unit tests that are required here :-)
It is not related to your question of course, but usually, the "shortest way to code" is also the "hardest way to maintain". For scientific applications, it is probably not a show stopper. But for IT applications, it is.
I think it has to be said. All the best.