I'm am trying to get all possible combinations of 11 values repeated 80 times but filter out cases where the sum is above 1. The code below achieves what I'm trying to do but takes days to run:
import numpy as np
import itertools
unique_values = np.linspace(0.0, 1.0, 11)
lst = []
for p in itertools.product(unique_values , repeat=80):
if sum(p)<=1:
lst.append(p)
The solution above would work but needs way too much time. Also, in this case I would have to periodically save the 'lst' into the disk and free the memory in order to avoid any memory errors. The latter part is fine, but the code needs days (or maybe weeks) to complete.
Is there any alternative?
unique_values = np.linspace(0.0, 1.0, 11)
real or is that an example? – Scribblenp.linspace(0.0, 1.0, 11)
instead ofrange(12)
? – Hexagonnp.linspace(0.0, 1.0, 11)
is real. The example above is exactly what I'm trying to get. If I usedrange(12)
I would not be able to check if the sum is below 1 – Claudetteclaudia