secour code:
vDists = dists.flatten()
vIndices = indices.flatten()
The method is to extract the serial number and data that have been searched, right?
2023/8/26 10:33:08
Yes, according to the code you provided, vDists and vIndices are one-dimensional arrays extracted from the nearest neighbor search results.
vDists flatten the two-dimensional array, dists, into a one-dimensional array with the flatten() function. It contains the distance between each source point and its nearest target point.
vIndices also flattens the two-dimensional array indices into a one-dimensional array using the flatten() function. It contains the index of the nearest target point in the nearest neighbor search results in the target point data.
This way, vDists can get the distance between each source point and its nearest target point, and vIndices can get the index of the nearest target point in the target point data.
2023/8/26 10:35:39
So the dists[:, 0] and dists[:, 1] operations extract because the two-digit array is a column representation:
(x,y),
(x1,y1)
And when you flatten it out to one dimension, it's rows (x,y), (x1,y1).
Is that right?
2023/8/26 10:35:48
Yes, your understanding is correct.
Depending on the code you provided, the dists array has the shape (n, 2), where n is the number of source points. Each element is a two-dimensional coordinate (x, y) that represents the distance between the source point and its corresponding nearest target point.
Using the dists[:, 0] operation, you can extract the first column of all elements, the x-coordinate distance. Using the dists[:, 1] operation, you can extract the second column of all elements, which is the y-coordinate distance.
When you call the flatten() function, the two-dimensional array is flattened into a one-dimensional array. By default, the flattening operation is row by row, so the order of the elements in the flattened one-dimensional array is row by row. In this case, the elements of a one-dimensional array are, in turn, (x, y) pairs.
So you can think of the one-dimensional array obtained by dists.flatten() as the distance between each source point and its nearest destination point, in order of the source points.