以下代码的输出是NOTHING。
if np.array([False]):
print("hello")
虽然我试图搜索它,但我不知道它是如何工作的。 Python 可以重载 if 吗?
以下是纯数组的情况。
if [False]:
print("hello")
输出是hello
你能告诉我如何编写 np.array 吗?
请您参考如下方法:
np.array([]) 似乎返回 False,0 和 False 也是如此
>>> bool(np.array([]))
False
>>> bool(np.array([0]))
False
>>> bool(np.array([False]))
False
如果列表中有任何项目,这里返回 true..
>>> bool([False]) ### the returned boolean value is based on the length of the list.
True
