def run_on_nested_arrays2(a, b, func, **param):
    """run func on each pair of element in a and b:
    a and b can be singlets, an array, an array of arrays, an array of arrays of arrays ...
    The return value is a flattened array
    """
    if isinstance(a, list):
        if not isinstance(b, list):
            raise Exception("can't combine list and non-list")
        if len(a) != len(b):
            raise Exception("Can't combine lists of different lengths")
        return([run_on_nested_arrays2(a_, b_, func, **param) for a_, b_ in zip(a, b)])
    else:
        return(func(a, b, **param))