Numpy.Array in Python list?

前端 未结 5 1433
[愿得一人]
[愿得一人] 2020-12-01 18:42

I\'ve got a list (used as a stack) of numpy arrays. Now I want to check if an array is already in the list. Had it been tuples for instance, I would simply have written some

5条回答
  •  时光说笑
    2020-12-01 19:02

    You can convert the array into a list by using tolist() and then do the check:

    my_list = [[1,1], [2,2]]
    
    print(np.array([1,1]).tolist() in my_list)
    print(np.array([1,2]).tolist() in my_list)
    

提交回复
热议问题