与布尔numpy数组VS PEP8 E712的比较
发布于 2021-01-29 14:57:31
PEP8 E712
要求“比较True
应为if cond is True:
或if cond:
”。
但是,如果我遵循此规则,则会PEP8
得到不同/错误的结果。为什么?
In [1]: from pylab import *
In [2]: a = array([True, True, False])
In [3]: where(a == True)
Out[3]: (array([0, 1]),)
# correct results with PEP violation
In [4]: where(a is True)
Out[4]: (array([], dtype=int64),)
# wrong results without PEP violation
In [5]: where(a)
Out[5]: (array([0, 1]),)
# correct results without PEP violation, but not as clear as the first two imho. "Where what?"
关注者
0
被浏览
86
1 个回答