Sorting 2D array in new 2D array (K-means clustering)

前端 未结 3 1464
心在旅途
心在旅途 2021-01-21 21:32

As input I have a 2D array PointXY[][] clusters, which looks like this:

[[23.237633,53.78671], [69.15293,17.138134], [23.558687,45.70517]] . . .
[[47         


        
3条回答
  •  温柔的废话
    2021-01-21 22:17

    Create a temporary float/double array of size [n][(n-1) * n] where input matrix is of the size [n][n-1].

    Compute the euclidean distances of all the points in the lower part of the matrix with all the points in the first row and store them at their respective positions in the temporary array.

    Create a copy of each temporary sub-array.

    Perform any sorting operation on the copy, preferably selection sort as you only need to sort the array partially until the lowest n-1 elements are found.

    Finally, create a new output array of size [n][n-1], correspond the lowest euclidean distances to their points, and store the sorted (n-1) element groups of (n-1) points right below their closest reference points.

提交回复
热议问题