我正在尝试使用 numpy.where 函数,如下所示:
x= np.where(segments==1000 and segments == 0)
然后我得到一个 ValueError:
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()
浏览其他一些线程,这似乎是预期的行为。但是,我不确定如何使用 numpy.any() 重新表述它。我无法获得正确的语法。
最佳答案
您可以使用括号和 &
或 np.logical_and
而不是 and
来构建您的条件:
(segments == 1000) & (segments == 0)
或:
np.logical_and(segments == 1000, segments == 0)
关于python:numpy.where 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26405751/