python - finding closest x,y position in one list to an x,y position in another? -
so have 2 2d lists x , y coordinates , want go through list1, , each point find closest x,y coordinates in list2. they're of different lengths, , it's okay if don't use points of list2 or if reuse points, long go through points once in list1. need shift location in lists of both points. tried using function found on site doesn't seem working:
def do_kdtree(combined_x_y_arrays,points): mytree = scipy.spatial.ckdtree(combined_x_y_arrays) dist, indexes = mytree.query(points) return dist,indexes #perhaps it's not doing wanted do. here tried: s_x = ([1.0,2.0,3.0]) s_y = ([1.5,2.5,3.5]) sdss_x = ([3.0,4.0,5.0]) sdss_y = ([3.5,4.5,5.5]) list1 = zip([s_x],[s_y]) list2 = zip([sdss_x],[sdss_y]) shift,place_in_array = do_kdtree(list1,list2)
and error get:
traceback (most recent call last): file "tester.py", line 23, in <module> shift,place_in_array = do_kdtree(list1,list2) file "tester.py", line 9, in do_kdtree mytree = scipy.spatial.ckdtree(combined_x_y_arrays) file "ckdtree.pyx", line 811, in scipy.spatial.ckdtree.ckdtree.__init__ (scipy/spatial/ckdtree.c:7157) valueerror: many values unpack (expected 2)
i impression means function wasn't expecting two-dimensional lists, mean function isn't doing wanted do. i'm not sure "indexes" returning , if point in list, hoping was. if that's case, tell me if there's existing function can use this?
you using zip
wrongly, won't create 2d-list you:
>>> s_x = ([1.0,2.0,3.0]) >>> s_y = ([1.5,2.5,3.5]) >>> list1_broken = zip([s_x],[s_y]) >>> print list1_broken [([1.0, 2.0, 3.0], [1.5, 2.5, 3.5])] >>> list1 = zip(s_x,s_y) >>> print list1 [(1.0, 1.5), (2.0, 2.5), (3.0, 3.5)]
Comments
Post a Comment