The Python Oracle

Numpy: Why is numpy.array([2]).any() > 1 False?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 Question
00:23 Accepted answer (Score 6)
00:48 Answer 2 (Score 3)
01:01 Thank you

--

Full question
https://stackoverflow.com/questions/1205...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #numpy

#avk47



ACCEPTED ANSWER

Score 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()



ANSWER 2

Score 3


Perhaps you are confusing it with this

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