SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clusters = {}
  2. for point_index, point in enumerate(D):
  3.     point_cluster = C[point_index]
  4.     if point_cluster not in clusters:
  5.         clusters[point_cluster] = []
  6.     clusters[point_cluster].append(point)
  7. final_result = [None] * len(clusters)
  8. for key in clusters:
  9.     centroid = get_centroid(clusters[key])
  10.     final_result[key] = centroid
  11.    
  12.  
  13. def get_centroid(cluster):
  14.     total_x = 0
  15.     total_y = 0
  16.     for x,y in cluster:
  17.         total_x += x
  18.         total_y += y
  19.     n = len(cluster)
  20.     return [1.0 * total_x / n, 1.0 * total_y / n]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top