python find the intersection point of two numpy array

Viewed 786

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>)

1 Answers
Related