Numpy.Array在Python列表中?

car*_*ett 12 python numpy

我有一个numpy数组的列表(用作堆栈).现在我想检查一个数组是否已经在列表中.如果它是元组,例如,我只会写一些相当于的东西(1,1) in [(1,1),(2,2)].但是,这对于numpy数组不起作用; np.array([1,1]) in [np.array([1,1]), np.array([2,2])]是一个错误(ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()).错误消息在这里没有帮助AFAIK,因为它指的是直接比较数组.

我很难相信这是不可能的,但我想有一些我不知道的东西.

Sve*_*ach 24

要测试a列表中是否包含等于的数组my_list,请使用

any((a == x).all() for x in my_list)
Run Code Online (Sandbox Code Playgroud)