I need from an array (or scalar) all possible combinations.
I have an Array np.array([0, 1, 0, 1])
or a scalar np.sum(np.array([0, 1, 0, 1]))
. Now i need all combinations such as:
[[2,0,0,0],
[1,1,0,0],
[1,0,1,0],
…
[0,0,1,1],
[0,0,0,2]]
The sum from an elements of all possible combinations can not exceed the sum of the scalar. I know the solution from "Using numpy to build an array of all combinations of two arrays“. But it does not help me for this problem. Have somebody any idea?