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?