I'm looking to find the median pairwise squared euclidean distance of an input array.
I know that I could do it using pdist:
from scipy.spatial.distance import pdist
dists = pdist(inp,'sqeuclidean')
np.median(dists)
But I need to repeat the process many times on very large input arrays. I'm doubtful that this could ever be extremely fast, as pairwise distance calculation is O(n^2) -- unless there's some clever way around that. But I know that the code for pdist isn't particularly efficient (source code is nested for-loops), so I was wondering if there's a way to speed it up, especially considering I just need the median.