pop = 100
number = list(range(pop+1))
comb = [c for c in itertools.product(number, repeat=3) if c[0] + c[1] + c[2] == pop]
This code generate all the triple of integer
number that sum
up to 100. I loop and check it, and it is fine. But than if I divide each tuple
by 100 they do not sum to 1.0, but some entries sum
to 0.99999999 or 1.00000002
poss_states = []
for i in range(len(comb)):
poss_states.append(np.divide(np.array(comb[i]),100))
To check if they sum to 1.0 I used:
for i in np.array(poss_states).sum(axis=1):
if i != 1.:
print(i)
I tried several ways to normalize but nothing works. How could I force the sum to be 1.0?