If condition in python not working properly over 2 dimensional array
I need to do is if any value inside my 2D array is greater than 0.3 it must display toxic but what it always does is print non-toxic even if there exist larger values like 0.6 or 0.4. I printed my values from the array just to see if there is an issue with loops but that's alright. I print the correct values
**for i in range(len( classes)):
for j in range(len(classes[i])):
print(classes[i][j])
if (classes[i][j] >0.3):
comment = " toxic"
else:
comment = "non toxic"**
One way would be to use the any
function, like this:
if any(element > 0.3 for group in classes for element in group):
comment = "toxic"
else:
comment = "non-toxic"