Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clusters = {}
- for point_index, point in enumerate(D):
- point_cluster = C[point_index]
- if point_cluster not in clusters:
- clusters[point_cluster] = []
- clusters[point_cluster].append(point)
- final_result = [None] * len(clusters)
- for key in clusters:
- centroid = get_centroid(clusters[key])
- final_result[key] = centroid
- def get_centroid(cluster):
- total_x = 0
- total_y = 0
- for x,y in cluster:
- total_x += x
- total_y += y
- n = len(cluster)
- return [1.0 * total_x / n, 1.0 * total_y / n]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement