def random_apply(p: float, func: Callable, *args, **kwargs):
    '\n    Returns a function that applies ``func`` with a given probability ``p``.\n\n    ``args`` and ``kwargs`` are passed to ``func`` as additional arguments.\n    '

    def wrapped(*args_, **kwargs_):
        if np.random.binomial(1, p):
            return func(*args_, *args, **kwargs_, **kwargs)
        return squeeze_first(args_)
    return wrapped
Returns a function that applies ``func`` with a given probability ``p``.

``args`` and ``kwargs`` are passed to ``func`` as additional arguments.
def random_apply(p: float, func: Callable, *args, **kwargs):
    '\n    Returns a function that applies ``func`` with a given probability ``p``.\n\n    ``args`` and ``kwargs`` are passed to ``func`` as additional arguments.\n    '

    def wrapped(*args_, **kwargs_):
        if np.random.binomial(1, p):
            return func(*args_, *args, **kwargs_, **kwargs)
        return squeeze_first(args_)
    return wrapped