Numpy.Array in Python list?

前端 未结 5 1426
[愿得一人]
[愿得一人] 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:13

    Sven's answer is the right choice if you want to compare the actual content of the arrays. If you only want to check if the same instance is contained in the list you can use

    any(a is x for x in mylist)
    

    One benefit is that this will work for all kinds of objects.

提交回复
热议问题