3
>>> import numpy
>>> numpy.array([2]) > 1
array([ True], dtype=bool)
>>> numpy.array([2]).any() > 1
False

Shouldn't any() test all elements of the array and return True?

2 Answers 2

6

It does return True. But (True > 1) == False. While the first part is 2 > 1 which of course is True.

As others posted, you probably want:

(numpy.array([2])  > 1).any()
Sign up to request clarification or add additional context in comments.

2 Comments

to be exact: numpy.array([2]).any() returns True
So any() should only be used on booleans. I get the idea now. Thanks!
3

Perhaps you are confusing it with this

>>> (numpy.array([2]) > 1).any()
True

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.