Recompute k-means centroids from cluster labels. labels[i] in {0,…,K−1} gives the cluster of row X[i]; each centroid is the mean of its cluster's points. A cluster with no points gets the zero vector.
Implement solve(X,labels,K).
Returns. Return a (K, d) float NumPy array of centroids.
Example 1
Input:
solve([[0.0, 0.0], [2.0, 0.0], [10.0, 10.0]], [0, 0, 1], 2)
Output:
[[1.0, 0.0], [10.0, 10.0]]
Example 2
Input:
solve([[1.0, 1.0], [3.0, 3.0]], [0, 0], 3)
Output:
[[2.0, 2.0], [0.0, 0.0], [0.0, 0.0]]
No results yet
Run your code to check it against the examples, or submit to run every test.