3

I have 2 numpy arrays, array_1 containing the source xy information and array_2 containing a long list of xy coordinates from a grid. My task is to add the nearest xy pair of array_2 to array_1.

After matching I am then going to take all points within a radius of the closest point and alter the grid value. (i.e. grid value = 1, if within radius grid value = 2)

I am a beginner in python and a first time poster. Thank you for any assistance

ali_m
  • 71,714
  • 23
  • 223
  • 298
  • 1
    I take it by "nearest" you mean Euclidean distance (http://en.wikipedia.org/wiki/Euclidean_distance)? Also, we like people to demonstrate some effort rather than just stating their requirements. – NPE Aug 18 '14 at 20:18
  • 2
    If you have scipy installed, you may be looking for `scipy.vq.vq` (for vector quantization). This will give you the index of the point in `array_2` which is closest to each point in `array_1`. And/or, you may be looking for `scipy.spatial.KDTree` which has methods for finding all points which are within a given radius of a point. – unutbu Aug 18 '14 at 20:35
  • 1
    Can I use 'scipy.spatial.KDTree' to find all point in a radius within array_2? – Greg Howard Aug 18 '14 at 21:34
  • 2
    @unutbu: I think you mean `scipy.cluster.vq.vq`. – Warren Weckesser Aug 19 '14 at 06:16
  • Hi! [This thread](http://stackoverflow.com/questions/27032562/local-maxima-in-a-point-cloud/) is about using `kdtree` to find all points in the vicinity of a certain point. Maybe it is a good starting point as you want to find all points in an array in the vicinity of every point in another array... – jkalden Dec 11 '14 at 13:00

0 Answers0