python报错The truth value of an array with more than one element is ambiguous.

情深不及哈士奇 2019-03-27 05:47:50
投影法做字符切割的一段程序,像素比较的时候会报错是为什么
def projection_line(array_vals, minimun_val, minimun_range):
start_i = None
end_i = None
line_ranges = []
'''
for index, item in enumerate(list1):
print index, item
'''
for i, val in enumerate(array_vals):
# 黑色像素起点
if val > minimun_val and start_i is None:
start_i = i
# 黑色像素区间
elif val > minimun_val and start_i is not None:
pass
# 黑色像素终点
elif val < minimun_val and start_i is not None:
# 黑色像素的长度
if i - start_i >= minimun_range:
end_i = i
#print(end_i - start_i)
# 记录此段黑色像素起始点
line_ranges.append((start_i, end_i))
start_i = None
end_i = None
# 白色像素区域
elif val < minimun_val and start_i is None:
pass
else:
raise ValueError("cannot parse this case...")
return line_ranges

报错信息:if val > minimun_val and start_i is None:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
...全文
2944 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧