Numpy: boolean comparison on two vectors -


i have 2 vectors (or 2 1 dimensional numpy arrays same number of elements) a , b want find number of cases have that:

a < 0 , b >0

but when type above (or similar) ipython get:

valueerror: truth value of array more 1 element ambiguous. use a.any() or a.all()

how supposed above operation?

thank you

i'm not understand you're trying do, might want ((a < 0) & (b > 0)).sum()

>>> array([-1,  0,  2,  0]) >>> b array([4, 0, 5, 3]) >>> < 0 array([ true, false, false, false], dtype=bool) >>> b > 0 array([ true, false,  true,  true], dtype=bool) >>> ((a < 0) & (b > 0)).sum() 1 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -