← 返回 apple 的题目列表K-Means Clustering: Compute Centroids After N Iterations
类型:online_judge
apple
Implement a k_means(clients, k, n) function. Given a 2D array clients with shape (N, 2) representing clients, an integer k representing the number of clusters, and an integer n representing the number of Assignment and Update steps. The function should correctly cluster the data and output the centroids of each cluster after n steps.
Input:
clients: A 2D array with shape (N, 2).
k: An integer representing the number of clusters.
n: An integer representing the number of Assignment and Update steps.
Output:
Returns a list containing the centroids of each cluster.
Example:
k_means([[1.0, 2.0], [2.0, 1.0], [3.0, 5.0], [8.0, 7.0]], 2, 10)
Assume the output is [centroid1, centroid2].
Example
Input
[[1.0, 2.0], [2.0, 1.0], [3.0, 5.0], [8.0, 7.0]] 2 10