In Python, are there builtin functions for elementwise map of boolean operators over tuples of lists

Posted by bshanks on Stack Overflow See other posts from Stack Overflow or by bshanks
Published on 2010-05-05T03:36:08Z Indexed on 2010/05/05 3:38 UTC
Read the original article Hit count: 192

Filed under:
|
|
|

For example, if you have n lists of bools of the same length, then elementwise boolean AND should return another list of that length that has True in those positions where all the input lists have True, and False everywhere else.

It's pretty easy to write, i just would prefer to use a builtin if one exists (for the sake of standardization/readability).

Here's an implementation of elementwise AND:

def eAnd(*args):
    return [all(tuple) for tuple in zip(*args)]

example usage:

>>> eAnd([True, False, True, False, True], [True, True, False, False, True], [True, True, False, False, True])
[True, False, False, False, True]

thx

© Stack Overflow or respective owner

Related posts about boolean

Related posts about python