The error message explains itself very well.
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all().
Array comparison return boolean:
Make sure your array comparison returns a boolean array. Methods any() and all() reduce values over the array either the value is logical_or or logical_and. Probably you also don’t need to check for equality.
What should bool return?
The main question is what should the bool(np.array([False, False, True])) have to return. There are many arguments.
- True, because bool(np.array(x)) should have to return same as bool(list(x)), and non empty lists.
- True, Because at least one element has to be true.
- False, because all the elements are not false value.
Since, the truth value of an array having more than one element is ambiguous so you have to use .any() or .all().
>>> v = np.array([1, 2, 3]) == np.array([1, 2, 4])
Array([True, True, False], dtype=bool)
You have to use np.allclose, if you are making comparisons of array for float data type.
>>> np.allclose(np.array([1, 2, 3_1e-8]), np.array([1, 2, 3]))
I hope you can understand and this answer will help to solve your problem.