列表似乎是随机变化的

时间:2019-05-09 10:43:01

标签: python append filtering

我试图递归地创建一个列表,该列表还会过滤已经具有相似值的列表。我无法直接比较它们,因为它们在10 ^ -4th和更高处有所不同。值必须具有0.09的最小间距。 但是,这似乎可行,当代码再次循环运行时,似乎会更改添加的值。

我曾尝试调试,但对错误发生的位置不知所措,它似乎并没有在特定事件中发生。

    for i in range(len(self.poses)):
        if self.poses[i].position.z > min_z:
           if min_x < abs(self.poses[i].position.x) < max_x:
            print('pos x', abs(self.poses[i].position.x))
            print('1.1')
            #max_x = self.poses[i].position.x
            if self.poses[i].position.y > 0.33:
            print('2.1')
     if self.poses[i].position.y < max_y:
        print('3.1')
        max_y = self.poses[i].position.y
        positions.x = self.poses[i].position.x
        positions.y = self.poses[i].position.y
        positions.z = self.poses[i].position.z

        if len(self.pickposes) == 0:
           print('posistion voor real cente:', positions)
           print('list empty')
           self.pickposes.append(positions)
           print(self.pickposes)
        else:
           tmp = 0
           loop_length = len(self.pickposes)
           for j in range(loop_length):
               if (abs(positions.y - self.pickposes[j].y) > 0.09):
                   print('y = ', positions.y)
                   print(j)
                   print("compared to : ", self.pickposes[j].y)
                   print('abs pose diff = ', abs(positions.y - self.pickposes[j].y))
                   tmp += 1
                   print('tmp in for loop =', tmp)

            print('tmp outside for =',tmp)
            print('loop length', loop_length)
            if loop_length <= self.index:
               if tmp == loop_length:
                  print('posistion to add to l', positions)
                  print("list of poses:", self.pickposes)
                  self.pickposes.append(positions)
                  print("list of poses:", self.pickposes)

我期望包含坐标的列表。那里没有一个dubbel,每个都围绕9。我得到的结果是:

    control_node: ('list of poses:', [x: 0.540071368217
    control_node: y: 0.578928947449
    control_node: z: 1.15875029564])
    control_node: 41
    control_node: ('pos x', 0.5376651287078857)
    control_node: 1.1
    control_node: 2.1
    control_node: 3.1
    control_node: ('y = ', 0.6925374269485474)
    control_node: 0
    control_node: ('compared to : ', 0.5789289474487305)
    control_node: ('abs pose diff = ', 0.1136084794998169)
    control_node: ('tmp in for loop =', 1)
    control_node: ('tmp outside for =', 1)
    control_node: ('loop length', 1)
    control_node: ('posistion to add to l', x: 0.537665128708
    control_node: y: 0.692537426949
    control_node: z: 1.15663790703)
    control_node: ('list of poses:', [x: 0.540071368217
    control_node: y: 0.578928947449
    control_node: z: 1.15875029564])
    control_node: ('list of poses:', [x: 0.540071368217
    control_node: y: 0.578928947449
    control_node: z: 1.15875029564, x: 0.537665128708
    control_node: y: 0.692537426949
    control_node: z: 1.15663790703])
    control_node: ('pos x', 0.5400646328926086)
    control_node: 1.1
    control_node: 2.1
    control_node: 3.1
    control_node: ('tmp outside for =', 0)
    control_node: ('loop length', 2)
    control_node: ('pos x', 0.5925142168998718)
    control_node: 1.1
    control_node: ('pos x', 0.5925142168998718)
    control_node: 1.1
    control_node: ('len list of poses', 2)
    control_node: ('list of poses:', [x: 0.540071368217
    control_node: y: 0.578928947449
    control_node: z: 1.15875029564, x: 0.540064632893
    control_node: y: 0.576979875565
    control_node: z: 1.15687179565])
    control_node: 50
    control_node: 51

更改自

x:0.537665128708 y:0.692537426949 z:1.15663790703

到 x:0.540064632893 y:0.576979875565 z:1.15687179565

是意外的,不应发生。控制节点使用步进器(数字41、50、51)以正确的顺序操纵其程序。之间没有步进打印,所以我很确定除了重新启动上层for循环外,在打印两个列表之间没有发生任何事情。

1 个答案:

答案 0 :(得分:0)

对观察到的行为没有太多解释。可以通过在添加时使用copy.deepcopy('x')来防止这种情况。