This loop computes the Mahalanobis distance of all the observations given `inv_cov` and computes `n_samples` weights from them.
This could be done for all observations in one shot: see MinCovDet code to obtain the vector of the observations Mahalanobis distances. Then you can sum the elements of that vector easily, or reweight the observations via a simple scalar product.
I think this wouldbe uch more efficient/elegant than the "for" loop.