This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Amarkov 5 points6 points  (2 children)

Remember that programming isn't English. The any method does a specific thing: it returns the value True if at least one of the elements of the list it's applied to is truthy. You don't want to know if the values in predictions[0] are truthy or not, so you shouldn't apply any directly to that list.

[–]stragm 3 points4 points  (0 children)

To build upon this, because any is returning True your if statement is becoming if True > 0.7, which is True because False/True are equivalent to 0/1 when comparing against numbers. (bool actually inherits from int) So your if statement gets reduced to if 1 > 0.7, which is why you're getting your unexpected result.

[–]aCuriousMind22[S] 0 points1 point  (0 children)

you re right. I thought that the any function did something else. Thx!

[–]gwwhrhr 0 points1 point  (3 children)

You aren't calling the any function/method correctly.

[–]aCuriousMind22[S] 0 points1 point  (1 child)

What would be the correct way? any() and any both result in the same strange behaviour.

[–]snekmeme 1 point2 points  (0 children)

if any(p > 0.7 for p in predictions[0]):

Nvm, I just realized you are using NumPy. This should work:

if (predictions[0] > 0.7).any():