dreamwalker
dreamwalker

Reputation: 1743

numpy any() returning a peculiar result

I have a numpy.ndarray ary

array([[ -8.34887715e-15],
       [ -8.57980353e-14],
       [ -7.28306304e-14]])

I am unable to understand the following:

ary.any() > 0.1

returns True even though each entry of ary is clearly below 0 (to my understanding this should evaluate to False).

If I however do

ary.any() > 1

this evaluates to False.

If anyone could shed some light on this that would be greatly appreciated!

Upvotes: 2

Views: 95

Answers (2)

tweaking
tweaking

Reputation: 350

well arr.any() is used on boolean when you do ary.any() this evaluates to true and true > 1 is certainly false

Upvotes: 0

Fred Foo
Fred Foo

Reputation: 363677

ary.any() returns True iff at least one element of ary is non-zero. You then check whether True > .1, which is true because True has the numerical value 1. What you meant was

(ary > .1).any()

Upvotes: 7

Related Questions