This function accepts a cloud of points, and returns those points that are within
delta distance of the average (mean) position.
def points_average(points,delta): """ this function will check, for every point in points what are the points that are near the point (below a distance delta) it will then average every such points, creating a new list of points. This will continue until we arrive at a fixed amount of points """ L = math.inf n = 0 while L > len(points): L = len(points) points2 =  for i in xrange(len(points)): pt = points[i] d = (pt-points[:,0])**2.+(pt-points[:,1])**2. pts = points[d<delta**2.] x = np.average(pts[:,0]) y = np.average(pts[:,1]) points2 += [[x,y]] points2 = np.array(points2) points = np.unique(points2,axis=0) print len(points) return points
The function can be tested with:
import numpy as np delta = 1 points = np.random.uniform(0,100,(500,2)) new_pts = simplify_by_avg_weighted(points,delta)
Please review the code for any improvements. In particular, I would like to replace the
for loop with a numpy vectorized version - any advice towards that would be welcome.