def random_choice(*args, **kwargs):
    w = kwargs.pop('w')
    w /= w.sum(axis=(- 1), keepdims=True)
    k = w.shape[(- 1)]
    if (w.ndim > 1):
        return np.row_stack([np.random.choice(k, p=w_) for w_ in w])
    else:
        return np.random.choice(k, *args, p=w, **kwargs)
def random_choice(*args, **kwargs):
    w = kwargs.pop('w')
    w /= w.sum(axis=(- 1), keepdims=True)
    k = w.shape[(- 1)]
    if (w.ndim > 1):
        return np.row_stack([np.random.choice(k, p=w_) for w_ in w])
    else:
        return np.random.choice(k, *args, p=w, **kwargs)