Reputation: 368
len([True for i in a if any([any(j == b[:, 0]) for j in i])])
This is my line of code. a
is a multidimensional list and b
is a nd.array. When I run it, it returns this error:
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Even though I used any()
at every place that is needed. Where's my mistake?
Edit: Values for the lists:
a = [[[[0, 0], [0, 0]]]]
b = np.array([[[[0, 0], [0, 0]], 0]])
Upvotes: 0
Views: 90
Reputation: 998
The problem is produced by:
any(j == b[:, 0])
use:
(j == b[:, 0]).any()
instead. Same for the outer any()
. Note that any()
can take an iterable, which np_array.any()
is a function from numpy.
Upvotes: 2