[英]python: Error with numpy.where
I am trying to use numpy.where function as follows: 我正在尝试使用numpy.where函数,如下所示:
x= np.where(segments==1000 and segments == 0)
and I get a ValueError: 我得到一个ValueError:
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()
Browsing through some other threads, seems this is the expected behaviour. 浏览其他线程,这似乎是预期的行为。 However, I am not sure how to reformulate this using numpy.any().
但是,我不确定如何使用numpy.any()重新构造它。 I cannot get the syntax correct.
我无法获得正确的语法。
You can build your condition using parenthesis and &
or np.logical_and
instead of and
: 您可以使用括号和
&
或np.logical_and
代替and
来建立条件。
(segments == 1000) & (segments == 0)
or: 要么:
np.logical_and(segments == 1000, segments == 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.