Generate all possible outcomes of k balls in n bins (sum of multinomial / categorical outcomes)
Suppose we have n bins in which we are throwing k balls. What is a fast (i.e. using numpy/scipy instead of python code) way to generate all possible outcomes as a matrix? For example, if n = 4 and k = 3 , we'd want the following numpy.array : 3 0 0 0 2 1 0 0 2 0 1 0 2 0 0 1 1 2 0 0 1 1 1 0 1 1 0 1 1 0 2 0 1 0 1 1 1 0 0 2 0 3 0 0 0 2 1 0 0 2 0 1 0 1 2 0 0 1 1 1 0 1 0 2 0 0 3 0 0 0 2 1 0 0 1 2 0 0 0 3 Apologies if any permutation was missed, but this is the general idea. The generated permutations don't have to be in any particular order, but the above list was convenient for categorically