Hi guys I have really simple question for you, let me explain shortly, for more detailed explanation please read below.
I want to order my 2D array which is an array of coordinates. However k= np.sort(k,0) is not working for me since it causes shuffling of y values. How can I solve this problem without losing my y values in an array of (x,y) ?
On the above you can see the result of np.sort(). It sorts all columns and shuffling the values, this makes the data useless.
Here is a longer explanation why I need that order:
I have a 2D array which are centers for K-means
centers = kmeans.cluster_centers_
plt.scatter(centers[:, 0], centers[:, 1], c='black', s=200, alpha=0.5);
I would like to sort this array with their x values because I want to use this in a RBF function like this:
plt.scatter(centers[:, 0], centers[:, 1], c='black', s=200, alpha=0.5);
rbfi = Rbf(centers[:, 0], centers[:, 1],function='gaussian')
u = rbfi(centers[:,0])
plt.plot(centers[:,0],u,'orange',linewidth=4)
plt.tick_params(labelcolor = 'white')
Since it is not ordered the function takes 2D points randomly and try to draw a line between them.
The result should look like something like this:




