some useful understanding of python‘s list

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值