我正在寻找到 python 中指定点的 3D 距离。现在,我正在使用 for 循环。但是计算起来有点慢。
这是python代码:
for i_y in xrange(0,500,100):
y = round(i_y/100.00,2)
for i_x in xrange(0, 800, 1):
x = round(i_x/100.00,2)
for i_z in xrange(500, 0, -1):
z = round(i_z/100.00,2)
for key in specifiedPoints.keys():
a = specifiedPoints[key]
subx1 = x-a.p1.x
suby1 = y-a.p1.y
subz1 = z-a.p1.z
subx2 = x-a.p2.x
suby2 = y-a.p2.y
subz2 = z-a.p2.z
subx3 = x-a.p3.x
suby3 = y-a.p3.y
subz3 = z-a.p3.z
distver1 = math.sqrt(subx1*subx1+suby1*suby1+subz1*subz1)
distver2 = math.sqrt(subx2*subx2+suby2*suby2+subz2*subz2)
distver3 = math.sqrt(subx3*subx3+suby3*suby3+subz3*subz3)
if distver1 <= 1 or distver2<=1 or distver3<=1:
print "close point:", x, y, z
我做了很多工作,但我找不到一个清晰的教程来显示 numpy 中的相等循环。
如何在 numpy 中进行此操作以加速循环?
谢谢