How to get center of set of points using Python
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))
If the set of points is a numpy array positions
of sizes N x 2, then the centroid is simply given by:
centroid = positions.mean(axis=0)
It will directly give you the 2 coordinates a a numpy array.
In general, numpy arrays can be used for all these measures in a vectorized way, which is compact and very quick compared to for
loops.