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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.