我下面的Python代碼很慢,有沒有可能用Numpy語句完全寫出這部分? m = len(self.man_list) s = len(self.newnew)self.zeroMatrix = np.zeros((m,s)) for k in range(m): a1 = self.man_list[k][2] b1 = self.man_list[k][0] a2 = self.man_list[k][3] b2 = self.man_list[k][1] for f, part in enumerate(self.extra_list): x1 = self.extra_list[f][0] y1 = self.extra_list[f][2] x2 = self.extra_list[f][1] y2 = self.extra_list[f][3] first = np.array((x1, y1)) second = np.array((x2, y2)) third = np.array((a1, b1)) forth = np.array((a2, b2)) dist1 = np.linalg.norm(first - third) dist2 = np.linalg.norm(second - forth) distance = (dist1 + dist2) self.zeroMatrix[k][f] = distance首先,我創建了一個零 ( self.zeroMatrix)矩陣。self.man_list并self.extra_list包含線的起點和終點坐標點。例如:self.man_list = [ [ [1,2], [3,4] ],...]self.extra_list = [ [ [11,30], [4, 10] ],...]我得到從第一個列表的每一行到另一個列表的每一行的距離,然后我在self.zeroMatrix.我非常感謝您的回答!
添加回答
舉報
0/150
提交
取消