[Numpy-discussion] logic problem

Ernest Adrogué eadrogue@gmx....
Mon Jan 18 13:52:30 CST 2010


18/01/10 @ 13:18 (-0600), thus spake Warren Weckesser:
> Ernest Adrogué wrote:
> > Hi,
> >
> > This is hard to explain. In this code:
> >
> > reduce(np.logical_or, [m1 & m2, m1 & m3, m2 & m3])
> >
> > where m1, m2 and m3 are boolean arrays, I'm trying to figure
> > out an expression that works with an arbitrary number of
> > arrays, not just 3. Any idea??
> >
> >   
> 
> If I understand the problem correctly, you want the result to be True
> whenever any pair of the corresponding elements of the arrays are True.

Exactly.

> This could work:
> 
> reduce(np.add, [m.astype(int) for m in mlist]) > 1
> 
> where mlist is a list of the boolean array (e.g. mlist = [m1, m2, m3] in
> your example).

Very clever. Thanks a lot!

> Warren
> > Bye.
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >   
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list