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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -