Numpy: necesito ayuda para comprender lo que sucede con el operador "in"
Agradecería que alguien pudiera ayudarme con esto (y explicar lo que está pasando).
Esto funciona
>>> from numpy import array
>>> a = array((2, 1))
>>> b = array((3, 3))
>>> l = [a, b]
>>> a in l
True
Pero esto no:
>>> 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()
El comportamiento que me gustaría replicar es:
>>> x = (2, 1)
>>> y = (3, 3)
>>> l2 = [x, y]
>>> z = (2, 1)
>>> z in l2
True
enga en cuenta que lo anterior también funciona con objetos mutables:
>>> x = [2, 1]
>>> y = [3, 3]
>>> l2 = [x, y]
>>> z = [2, 1]
>>> z in l2
True
Por supuesto, sabiendo que:
>>> (a < b).all()
True
Intenté (y fallé):
>>> (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()