使用.remove()会产生错误"使用a.any()或a.all()"

时间:2016-10-22 18:14:31

标签: python python-3.x numpy pygame

我已经查看了有关此错误的其他几个问题,但我仍然无法弄清楚错误是什么。

要选择单位,我有从类中抽取的列表/数组:

unit_orc_grunt = Unit("Grunt",[35,70,105,140,175,210,245,280,315,350],[35,70,105,140,175,210,245,280,315,350])

positions = numpy.array([
                            [unit_orc_grunt.locationx[0],unit_orc_grunt.locationy[0]],
                            [unit_orc_grunt.locationx[1],unit_orc_grunt.locationy[1]],
                            [unit_orc_grunt.locationx[2],unit_orc_grunt.locationy[2]],
                            [unit_orc_grunt.locationx[3],unit_orc_grunt.locationy[3]],
                            [unit_orc_grunt.locationx[4],unit_orc_grunt.locationy[4]],
                            [unit_orc_grunt.locationx[5],unit_orc_grunt.locationy[5]],
                            [unit_orc_grunt.locationx[6],unit_orc_grunt.locationy[6]],
                            [unit_orc_grunt.locationx[7],unit_orc_grunt.locationy[7]],
                            [unit_orc_grunt.locationx[8],unit_orc_grunt.locationy[8]],
                            [unit_orc_grunt.locationx[9],unit_orc_grunt.locationy[9]],
                        ])

not_selected = [
                    positions[0],
                    positions[1],
                    positions[2],
                    positions[3],
                    positions[4],
                    positions[5],
                    positions[6],
                    positions[7],
                    positions[8],
                    positions[9]
                ]

selected = []

然后我在游戏循环中有这个:

        elif button_type[0] == 1:
            for position in positions:
                if numpy.any(position == not_selected) and numpy.any(position != selected) and mouse_position[0] >= position[0] and mouse_position[0] <= position[0] + character_width and mouse_position[1] >= position[1] and mouse_position[1] <= position[1] + character_height:
                    selected.append(position)
                    print("Position = ",position)
                    print("Selected Units = ",selected)

这样可以正常工作,然后从列表中选择所选单位&#39;然而,当我尝试添加行not_selected.remove(position)时,我收到错误:

        elif button_type[0] == 1:
            for position in positions:
                if numpy.any(position == not_selected) and numpy.any(position != selected) and mouse_position[0] >= position[0] and mouse_position[0] <= position[0] + character_width and mouse_position[1] >= position[1] and mouse_position[1] <= position[1] + character_height:
                    selected.append(position)
                    print("Position = ",position)
                    print("Selected Units = ",selected)
                    not_selected.remove(position)

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

为什么selected.append(position)有效但not_selected.remove(position)在这里无效?我该如何解决这个问题?

0 个答案:

没有答案