I would appreciate it if someone would help me with this (and explain what is happening).
It works:
>>> from numpy import array >>> a = array((2, 1)) >>> b = array((3, 3)) >>> l = [a, b] >>> a in l True
But this is not so:
>>> 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()
The behavior I would like to reproduce is as follows:
>>> x = (2, 1) >>> y = (3, 3) >>> l2 = [x, y] >>> z = (2, 1) >>> z in l2 True
Note that the above also works with mutable objects:
>>> x = [2, 1] >>> y = [3, 3] >>> l2 = [x, y] >>> z = [2, 1] >>> z in l2 True
Of course, knowing that:
>>> (a < b).all() True
I tried (and could not):
>>> (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()
source share