python: numpy.where出错
我正在尝试使用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()来重新写这个。我总是写错语法。
1 个回答
5
你可以用括号和 &
或者 np.logical_and
来构建你的条件,而不是用 and
:
(segments == 1000) & (segments == 0)
或者:
np.logical_and(segments == 1000, segments == 0)