How to achieve fast "vector clustering" sort?
I have n c-dimensional vectors that formed into a matrix A with the shape of (n, c), how can I perform a quick sort such that the vectors with low Euclidean distances are as close as possible, and the vectors with high distances are as far as possible?
For example, I have
A = [[0, 3], [0, 0], [0, 1]],

and the solution can be
A_sorted = [[0, 3], [0, 1], [0, 0]].

Explain: Because the original A has a total weighted distance sum of 3x1+1x1+2x2 = 7, and A_sorted has 2x1+1x1+3x2 = 8.
Mathematically, the goal is to maximize the total weighted distance sum.
For the 1-dimensional case, this can be achieved by some APIs like sort() in Numpy or PyTorch, and my main concern is if there exists a fast implementation when c ≥ 2 with a time complexity of O(nlog(n))?
After a long struggle, I failed. Could you please do me a favor?

I believe this is what you want:
def d(l):
    return math.sqrt(sum([x**2 for x in l]))

A = [[0, 3], [0, 0], [0, 1]]

dists = [d(el) for el in A]
sorted_vecs = sorted(zip(A, dists), key=lambda x: -x[1])
[x[0] for x in sorted_vecs]

Returns
[[0, 3], [0, 1], [0, 0]]

It's O(nlog(n))
