SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 74 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.     if point_index not in clusters:
  4.         clusters[point_index] = []
  5.     clusters[point_index].append(point)
  6. final_result = [None] * len(clusters)
  7. for key in clusters:
  8.     centroid = get_centroid(clusters[key])
  9.     final_result[key] = centroid
  10.    
  11.  
  12. def get_centroid(cluster):
  13.     total_x = 0
  14.     total_y = 0
  15.     for x,y in cluster:
  16.         total_x += x
  17.         total_y += y
  18.     n = len(cluster)
  19.     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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top