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 something equivalent to (1,1) in [(1,1),(2,2)]. However, this does not work for numpy arrays; np.array([1,1]) in [np.array([1,1]), np.array([2,2])] is an error (ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()). The error message does not help here AFAIK, as it is referring to comparing arrays directly.
I have a hard time beliving it wouldn't be possible, but I suppose there's something I'm missing.
解决方案
To test if an array equal to a is contained in the list my_list, use
any((a == x).all() for x in my_list)