简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM