I think that using sklearn.metrics.pairwise.euclidean_distances, with squared=True would be cleaner and faster here. We tend to prefer this in scikit-learn.