Буду признателен, если кто-нибудь поможет мне с этим (и объяснит, что происходит).
Это работает:
>>> from numpy import array
>>> a = array((2, 1))
>>> b = array((3, 3))
>>> l = [a, b]
>>> a in l
True
Но это не так:
>>> c = array((2, 1))
>>> c in l
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Поведение, которое я хотел бы воспроизвести:
>>> x = (2, 1)
>>> y = (3, 3)
>>> l2 = [x, y]
>>> z = (2, 1)
>>> z in l2
True
Обратите внимание, что выше также работает с изменяемыми объектами:
>>> x = [2, 1]
>>> y = [3, 3]
>>> l2 = [x, y]
>>> z = [2, 1]
>>> z in l2
True
Конечно, зная, что:
>>> (a < b).all()
True
Я пытался (и не смог):
>>> (c in l).all()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()