【发布时间】:2020-12-10 07:48:21
【问题描述】:
我在 python 3 中观察到以下行为:
>>> ([False, True] and [True, True])
[True, True]
>>> ([False, True] or [True, True])
[False, True]
我的预期正好相反:
[False, True] and [True, True] = [False and True, True and True] = [False, True]
[False, True] or [True, True] = [False or True, True or True] = [True, True]
观察到的行为有什么意义,我怎样才能达到预期的行为?
【问题讨论】:
-
为什么你期待
[False, True] and [True, True] = [False and True, True and True]? -
@juanpa.arrivillaga 这就是它在 R 和 Fortran 中的工作方式。他们逐元素评估向量。
-
R 和 Fortran 使用的是数组,而不是普通的旧列表(因此 numpy 填补了空白)
标签: python python-3.x boolean