def calculateCentroid(self):
if len(self.points) > 0 :
# Finds a virtual center point for a group of n-dimensional points
numPoints = len(self.points)
# Get a list of all coordinates in this cluster
coords = [p.coords for p in self.points]
print('cluster has: '+ str(numPoints) + ' point')
# Reformat that so all x's are together, all y'z etc.
unzipped = zip(*coords)
# Calculate the mean for each dimension
centroid_coords = [math.fsum(dList)/numPoints for dList in unzipped]
return Point(centroid_coords,'Centroid')
else:
return self.centroid
评论列表
文章目录