performance - Duplicate removal within a certain distance in Python -


i have 2 numpy.arrays of points (shapes (m,2) , (n,2)) this:

a = numpy.array([[1,2],[3,4]]) b = numpy.array([[5,6],[7,8],[9,2]]) 

i need merge them array next condition:

if there 2 points distance less or equal epsilon, leave one

i have code, it's slow:

import numpy np  eps = 0.1 = np.array([[1,2],[3,4]]) b = np.array([[5,6],[7,8],[9,2]])  point in b:     if not (np.amin(np.linalg.norm(a-point)) <= eps):         = np.append(  ,  [point], axis=0) 

what best way using numpy?

thanks lot!

you calculate delaunay triangulation first, list of neighboring points can extracted:

import numpy np itertools import product scipy.spatial import delaunay  eps = 3.  # choose value, filters out points = np.array([[1,2],[3,4]]) b = np.array([[5,6],[7,8],[9,2]])  # triangulate points: pts = np.vstack([a, b]) tri = delaunay(pts)  # extract edges: si_idx = [[0, 1], [0, 2], [1, 2]]  # edge indeces in tri.simplices edges = [si[i] si, in product(tri.simplices, si_idx)] dist_edges = [np.linalg.norm(tri.points[ii[0]] - tri.points[ii[1]])               ii in edges]  # calculate distances  # list points closer eps: ee, d in zip(edges, dist_edges):     if d < eps:         print("|p[{}] - p[{}]| = {}".format(ee[0], ee[1], d)) 

as @david wolever noted, not clear question, how remove points merged list.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -