Reputation: 11016
I am trying to use numpy.where function as follows:
x= np.where(segments==1000 and segments == 0)
and I get a 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(). I cannot get the syntax correct.
Upvotes: 4
Views: 1491
Reputation: 59005
You can build your condition using parenthesis and &
or np.logical_and
instead of and
:
(segments == 1000) & (segments == 0)
or:
np.logical_and(segments == 1000, segments == 0)
Upvotes: 5