How to get center of set of points using Python

Dominik Szopa picture Dominik Szopa · Dec 4, 2010 · Viewed 36.5k times · Source

I would like to get the center point(x,y) of a figure created by a set of points.

How do I do this?

Answer

Colin picture Colin · Dec 4, 2010

If you mean centroid, you just get the average of all the points.

x = [p[0] for p in points]
y = [p[1] for p in points]
centroid = (sum(x) / len(points), sum(y) / len(points))