I need to find the best way to generate an array that contains all possible combinations of the values 0 to 1.0 with a 0.1 increment, where the sum of each combination is exactly equal to 1.
I have done this for array of length 3 with this code:
portfolios = []
for i in np.arange(0,1.1,0.1):
for j in np.arange(0,1-i,0.1):
k = 1 - i - j
x = [i,j,k]
portfolios.append(x)
portfolios = np.array(portfolios)
Which gives me the following
print(portfolios)
#Output:
array([[0. , 0. , 1. ],
[0. , 0.1, 0.9],
[0. , 0.2, 0.8],
[0. , 0.3, 0.7],
[0. , 0.4, 0.6],
[0. , 0.5, 0.5],
[0. , 0.6, 0.4],
[0. , 0.7, 0.3],
[0. , 0.8, 0.2],
[0. , 0.9, 0.1],
[0.1, 0. , 0.9],
[0.1, 0.1, 0.8],
[0.1, 0.2, 0.7],
[0.1, 0.3, 0.6],
[0.1, 0.4, 0.5],
[0.1, 0.5, 0.4],
[0.1, 0.6, 0.3],
[0.1, 0.7, 0.2],
[0.1, 0.8, 0.1],
[0.2, 0. , 0.8],
[0.2, 0.1, 0.7],
[0.2, 0.2, 0.6],
[0.2, 0.3, 0.5],
[0.2, 0.4, 0.4],
[0.2, 0.5, 0.3],
...
[0.7, 0. , 0.3],
[0.7, 0.1, 0.2],
[0.7, 0.2, 0.1],
[0.8, 0. , 0.2],
[0.8, 0.1, 0.1],
[0.9, 0. , 0.1]])
However, I want to do this for an array of length 7. That is, my desired output should look something like this:
#Desired output
array([[0. , 0., 0., 0., 0., 0., 1.],
[0. , 0., 0., 0., 0., 0.1, 0.9],
[0. , 0., 0., 0., 0., 0.2, 0.8],
...
[0.2, 0.8, 0., 0., 0., 0., 0.],
[0.1, 0.9, 0., 0., 0., 0., 0.],
[.1, 0., 0., 0., 0., 0., 0.]])
Is there a smart way to extend my previous code? Open to all suggestions and alternative approaches.