请任何人都可以解释我这个结果代码
x = np.array([9, 5])
y = np.array([16, 12])
np.logical_or(x < 5, y > 15)
结果-〉array([ True, False])
自:
np.logical_or(x < 5, y > 15)
x < 5 = [False, False], y > 15 = [True, False]
我想应该是:
[False or False, False or True] = [False, True]
实际上Python给出的结果是这样的:
[False or True, False or False] = [True, False]
为什么结果不是[False,True],而实际上python给出的结果是[True,False]?这与操作np.logical_or(x < 5, y > 15)
的顺序不匹配
即使我尝试了ChatGPT的解释,我仍然没有清楚地理解这个概念。
如果有人能一步一步地详细解释python进程的背景,我将不胜感激。
1条答案
按热度按时间ippsafx71#
你对结果的解释是错误的。Numpy的
logical_or
可以有几个参数作为过滤器。在你的例子中,输入参数是x < 5
和y > 15
。然后它用or
运算符将它们组合在一起。x < 5
将导致:[False, False]
y > 15
将导致:[True, False]
[False or True, False or False] = [True, False]