I have two numpy array that describes a spatial curve, that are intersected on one point and I want to find the nearest value in both array for that intersection point, I have this code that works fine but its to slow for large amount of points.
from scipy import spatial def nearest(arr0, arr1): ptos = [] j = 0 for i in arr0: distance, index = spatial.KDTree(arr1).query(i) ptos.append([distance, index, j]) j += 1 ptos.sort() return (arr1[ptos[0][1]].tolist(), ptos[0][1], ptos[0][2]) the result will be (<point coordinates>,<position in arr1>,<position in arr0>)
x,y,zof a spatial line so nx3 the numbers of point are not fixed, but for now may work for a line in ax,yplane so nx2 may work too