Luca
Luca

Reputation: 11016

python: Error with numpy.where

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

Answers (1)

Saullo G. P. Castro
Saullo G. P. Castro

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

Related Questions