[Numpy-discussion] varargs for logical_or, etc

Neal Becker ndbecker2@gmail....
Tue Jun 5 08:54:22 CDT 2012


I think it's unfortunate that functions like logical_or are limited to binary.

As a workaround, I've been using this:

def apply_binary (func, *args):
    if len (args) == 1:
        return args[0]
    elif len (args) == 2:
        return func (*args)
    else:
        return func (
            apply_binary (func, *args[:len(args)/2]),
            apply_binary (func, *args[(len(args))/2:]))

Then for example:

punc2 = np.logical_and (u % 5 == 4,
                       apply_binary (np.logical_or, u/5 == 3, u/5 == 8, u/5 == 
13))




More information about the NumPy-Discussion mailing list