【发布时间】:2021-03-03 15:54:45
【问题描述】:
假设一个点或节点的列表。他们每个人都有 x y 和 z 坐标。两点 i 和 j 之间的距离等于D(i,j)= sqrt((xi-xj)^2+(yi-yj)^2+(zi-zj)^2)。这里我得到了 400000 个数据点。
现在,我想选择一组它们之间具有相等距离的节点(之前指定的间距 --> 0.05)。因此选择的点是均匀分布的。
如果使用 while 循环运行,完成整个数据集大约需要 3 小时。 寻找最快的方法。
no_rows = len(df)
i = 1
while i < no_rows:
a1 = df.iloc[i-1, 1]
a2 = df.iloc[i, 1]
b1 = df.iloc[i-1, 2]
b2 = df.iloc[i, 2]
c1 = df.iloc[i-1, 3]
c2 = df.iloc[i, 3]
dist = np.round(((a2-a1)**2+(b2-b1)**2+(c2-c1)**2)**0.5,5)
df.iloc[i, 6]= dist
if dist < 0.05000:
df = df.drop(i)
df.reset_index(drop = True, inplace = True)
no_rows = len(df)
i = i-1
i+=1
【问题讨论】:
-
嗨@Arun,看看这个方法,看看它是否适合你:stackoverflow.com/questions/1401712/…。我认为答案可能是将您的数据放入一个数组中,然后使用 numpy 的矢量化操作来加快速度。
标签: python pandas scipy spatial kdtree