The truth value of an array with more than one element is ambiguous.
- pandas
- numpy
>>> x = np.arange(10)
>>> if x<5: print('Small!')
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
That x<5
is not actually a boolean value, but an array of 10 bools, indicating which values are under 5.
If what the user wants is (x<5).any()
or (x<5).all()
and they just failed to read the error, close as a dup (separate questions for numpy
and pandas
).
If what the user wanted was to use x<5
as a mask array to do further array processing instead of whatever loop with an if
or while
they were attempting, that could be a good question, or a “I don’t want to read the numpy tutorial, I want you to write me a new numpy tutorial instead” question, but probably not a dup.