Simple question, confusing output: np.array([-1, 0, 1]).any() < 0 out: False (why??) but: np.any(np.array([-1, 0, 1])) out: True (as expected)
Acoording to documentation both commands should be equivalent, but they aren't.
Simple question, confusing output: np.array([-1, 0, 1]).any() < 0 out: False (why??) but: np.any(np.array([-1, 0, 1])) out: True (as expected)
Acoording to documentation both commands should be equivalent, but they aren't.
Numpy is used to provide a method and a function that do the exact same thing.
assert my_array.any() == numpy.any(my_array)
Here my_array.any() is the method and numpy.any(my_array) is the function.
It both return a Boolean. Here you ask why np.array([-1, 0, 1]).any() < 0
returns False
because np.array([-1, 0, 1]).any()
is True
which is equal to the value 1
and you ask if it is < 0
which is False
.
import numpy as np
my_array = np.array([-1, 0, 1])
assert my_array.any() == True
assert my_array.any() == 1
assert my_array.any() > 0
assert np.any(my_array) == True
assert my_array.any() == np.any(my_array)