python报错ValueError: The truth value of an array with more than one element is ambiguous. Use a.any()
程序员文章站
2022-05-27 12:50:16
...
python报了一个比较少见的错:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
后来发现错误发生在如下语句:
if tree.result != None: # 当到达叶子节点,则直接返回tree.result作为预测标签
return tree.result
当result是一个数值时,该句不会报错。但当result是一个array结构时,就会报错。
主要原因是:!=
这个判断符号只能针对数值,如果result不是数值,该判断语句就不知道怎么判断,所以报错。
修改为如下,即采用is not
即可对任何数据类型都进行判断,错误消失。
if tree.result is not None: # 当到达叶子节点,则直接返回tree.result作为预测标签
return tree.result
推荐阅读
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous
-
python报错ValueError: The truth value of an array with more than one element is ambiguous. Use a.any()
-
Python报错:The truth value of an array with more than one element is ambiguous
-
Python ValueError: The truth value of an array with more than one element is ambiguous.
-
成功解决Python的ValueError: The truth value of an array with more than one element is ambiguous
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous
-
[numpy问题]The truth value of an array with more than one element is ambiguous.
-
学习随笔-ValueError: The truth value of an array with more than one element is ambiguous
-
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous