numpy any()的意外结果

问题描述 投票:0回答:1

最有可能我缺少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)
python-3.x numpy any
1个回答
1
投票
# 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
© www.soinside.com 2019 - 2024. All rights reserved.