문제 설명
두 좌표 배열 간의 대응 관계 찾기 (Find correspondence between 2 arrays of coordinates)
3D 좌표에 해당하는 두 개의 큰 2D 배열(3x100,000)이 있고 각 대응의 인덱스를 찾고 싶습니다.
예:
mat1 = np.array([[0,0,0],[0,0,0],[0,0,0],[10,11,12],[1,2,3]]).T
mat2 = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]]).T
그래서 여기 3과 0의 인덱스를 가져와야 합니다. 그리고 약 100,000개의 좌표에서 각 대응을 찾아야 합니다. 이 작업을 수행하는 특정 기능이 Python에 있습니까? for 루프를 적용하는 것은 문제가 될 수 있습니다.
res = [3,0]
요약하자면, 제 필요 사항은 다음과 같습니다.
참조 솔루션
방법 1:
We can use Cython‑powered kd‑tree
for quick nearest‑neighbor lookup ‑
In [77]: from scipy.spatial import cKDTree
In [78]: d,idx = cKDTree(mat2.T).query(mat1.T, k=1)
In [79]: idx[np.isclose(d,0)]
Out[79]: array([3, 0])
(by user3601754、Divakar)