I have some array with integers, and for loop. I am trying to test if some specific elements in array is bigger or smaller that some integer. This code explain it better:
array = [1,2,3,4,5]
for i in range(5):
if array[i] >= 3:
print(sometext)
else:
print(othertext)
But i got an ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
SOLUTION: I did indent it properly. This above is just simplification(some stupid example) of my code. I found where the error is. It is because I initialized array with numpy as
a = numpy.empty(5)
and not like this:
a = [0 for i in range(5)]
Thank you everybody for your help
list
. However, your error message seems to come fromnumpy
. You should provide a minimal reproducible example, although your question is almost certainly a duplicate – Krasnoyarsk