【问题标题】:Python: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()Python:ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()
【发布时间】:2014-07-04 09:01:17
【问题描述】:

这是我的代码:

for ts, blob in izip(ts_list, blobs):
    ts = simplecvimg.track("camshift", i, fgmask,b.boundingBox())
    print(ts)

这是我得到的错误:

  if not ts and not img:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

虽然我从这里了解ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() 为什么会出现此错误,但我不知道在我的情况下如何处理此错误。任何帮助将不胜感激!

【问题讨论】:

标签: python python-2.7 simplecv


【解决方案1】:

tsimg 是一个 numpy 数组...因此它不知道 not <numpy.array> 是什么意思

你可能想要if len(ts) > 0 and len(img) > 0,或者if ts is not None或者类似的东西

>>> import numpy
>>> not numpy.array([1,2,3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous.
 Use a.any() or a.all()

【讨论】:

  • 声明如下:ts_list = [],其中ts为ts_list中的每个元素,f,img=cam.read()。我尝试了您建议的所有 3 件事,但均无济于事。
猜你喜欢
  • 2020-05-12
  • 2018-12-01
  • 2016-01-26
  • 2017-04-10
  • 2020-07-02
相关资源
最近更新 更多