numpy any() 的意外结果

unexpected result with numpy any()

很可能我在 any() 函数中遗漏了一些东西,它说: Returns True if any of the elements of a evaluate to True.

所以在我下面的例子中,我希望 true 作为输出,作为一个元素 count[0] 大于2。但是,输出是FALSE

我犯了什么愚蠢的错误?!

最小示例:

count = np.zeros(10)
count[0] += 4
count[5] += 1
print(np.any(count,axis=0) > 2)
# parentheses:

np.any(count,axis=0)
#output: True

np.any(count, axis=0)>2
# is a boolean expression. It evaluates to False, because True is not larger than 2.

# So:
np.any(count>2, axis=0)

# should do what you want