Create lists with 3 levels, containing every combination of sub list(s) values












0














I am currently stuck with the following problem (I could not find solution already on here that really fitted this):



I have three lists a = [a, b, c], b = [1, 2, 3] and c = [0.1, 0.2, 0.3].



I would like to create a lists of list of lists (maybe I should be using numpy arrays?), that contains all combinations between these lists, but where each element in each sub list are also iterated in a bruce-force like pattern, such that the following is generated:



mylist = [[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.1]],
[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.2]],
...
[[a, 2, 0.3], [b, 3, 0.3], [c, 1, 0.1]],
...
[[a, 1, 0.3], [b, 1, 0.3], [c, 1, 0.3]],
...
[[a, 3, 0.3], [b, 1, 0.3], [c, 3, 0.1]]
...
[[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]]]



I appreciate that this would equate to an extremely large list (happy to be advised on a better approach!), but I effectively need to have a three dimensional list with each sublist e.g. mylist[0], passed as list containing individual sublist parameters (e.g., [[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]] to an algorithm which will use them as input. This 3-D list forms effectively the entire parameter space that will need to be "searched". Thus you can see why the following combination examples:



[[a, 1, 0.3], [b, 2, 0.3], [c, 2, 0.3]],
[[a, 3, 0.1], [b, 1, 0.3], [c, 2, 0.1]]



Are important, because they serve as a unique of parameters for algorithmic input.



Really grateful for any guidance on this, thanks.










share|improve this question




















  • 1




    Welcome to StackOverflow! So, what have you tried?
    – Andreas
    Nov 23 at 1:33










  • what is the output dimension?
    – kevinkayaks
    Nov 23 at 1:45










  • @kevinkayaks, the output dimensions are as follows:
    – Ryan
    Nov 23 at 9:43










  • ` x = [[[a],[0],[0.1]],[[a],[0],[0.1]],[[a],[0],[0.1]]], y = all combinations of above`. Does that make sense? So 3 dimensions, where y equals all the combinations for a row as described above.
    – Ryan
    Nov 23 at 9:49










  • @Andreas I had try to have recursive loops for each list, then using iterools with permutations, but could not get the right output as per above.
    – Ryan
    Nov 23 at 10:11
















0














I am currently stuck with the following problem (I could not find solution already on here that really fitted this):



I have three lists a = [a, b, c], b = [1, 2, 3] and c = [0.1, 0.2, 0.3].



I would like to create a lists of list of lists (maybe I should be using numpy arrays?), that contains all combinations between these lists, but where each element in each sub list are also iterated in a bruce-force like pattern, such that the following is generated:



mylist = [[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.1]],
[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.2]],
...
[[a, 2, 0.3], [b, 3, 0.3], [c, 1, 0.1]],
...
[[a, 1, 0.3], [b, 1, 0.3], [c, 1, 0.3]],
...
[[a, 3, 0.3], [b, 1, 0.3], [c, 3, 0.1]]
...
[[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]]]



I appreciate that this would equate to an extremely large list (happy to be advised on a better approach!), but I effectively need to have a three dimensional list with each sublist e.g. mylist[0], passed as list containing individual sublist parameters (e.g., [[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]] to an algorithm which will use them as input. This 3-D list forms effectively the entire parameter space that will need to be "searched". Thus you can see why the following combination examples:



[[a, 1, 0.3], [b, 2, 0.3], [c, 2, 0.3]],
[[a, 3, 0.1], [b, 1, 0.3], [c, 2, 0.1]]



Are important, because they serve as a unique of parameters for algorithmic input.



Really grateful for any guidance on this, thanks.










share|improve this question




















  • 1




    Welcome to StackOverflow! So, what have you tried?
    – Andreas
    Nov 23 at 1:33










  • what is the output dimension?
    – kevinkayaks
    Nov 23 at 1:45










  • @kevinkayaks, the output dimensions are as follows:
    – Ryan
    Nov 23 at 9:43










  • ` x = [[[a],[0],[0.1]],[[a],[0],[0.1]],[[a],[0],[0.1]]], y = all combinations of above`. Does that make sense? So 3 dimensions, where y equals all the combinations for a row as described above.
    – Ryan
    Nov 23 at 9:49










  • @Andreas I had try to have recursive loops for each list, then using iterools with permutations, but could not get the right output as per above.
    – Ryan
    Nov 23 at 10:11














0












0








0







I am currently stuck with the following problem (I could not find solution already on here that really fitted this):



I have three lists a = [a, b, c], b = [1, 2, 3] and c = [0.1, 0.2, 0.3].



I would like to create a lists of list of lists (maybe I should be using numpy arrays?), that contains all combinations between these lists, but where each element in each sub list are also iterated in a bruce-force like pattern, such that the following is generated:



mylist = [[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.1]],
[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.2]],
...
[[a, 2, 0.3], [b, 3, 0.3], [c, 1, 0.1]],
...
[[a, 1, 0.3], [b, 1, 0.3], [c, 1, 0.3]],
...
[[a, 3, 0.3], [b, 1, 0.3], [c, 3, 0.1]]
...
[[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]]]



I appreciate that this would equate to an extremely large list (happy to be advised on a better approach!), but I effectively need to have a three dimensional list with each sublist e.g. mylist[0], passed as list containing individual sublist parameters (e.g., [[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]] to an algorithm which will use them as input. This 3-D list forms effectively the entire parameter space that will need to be "searched". Thus you can see why the following combination examples:



[[a, 1, 0.3], [b, 2, 0.3], [c, 2, 0.3]],
[[a, 3, 0.1], [b, 1, 0.3], [c, 2, 0.1]]



Are important, because they serve as a unique of parameters for algorithmic input.



Really grateful for any guidance on this, thanks.










share|improve this question















I am currently stuck with the following problem (I could not find solution already on here that really fitted this):



I have three lists a = [a, b, c], b = [1, 2, 3] and c = [0.1, 0.2, 0.3].



I would like to create a lists of list of lists (maybe I should be using numpy arrays?), that contains all combinations between these lists, but where each element in each sub list are also iterated in a bruce-force like pattern, such that the following is generated:



mylist = [[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.1]],
[[a, 1, 0.1], [b, 1, 0.1], [c, 1, 0.2]],
...
[[a, 2, 0.3], [b, 3, 0.3], [c, 1, 0.1]],
...
[[a, 1, 0.3], [b, 1, 0.3], [c, 1, 0.3]],
...
[[a, 3, 0.3], [b, 1, 0.3], [c, 3, 0.1]]
...
[[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]]]



I appreciate that this would equate to an extremely large list (happy to be advised on a better approach!), but I effectively need to have a three dimensional list with each sublist e.g. mylist[0], passed as list containing individual sublist parameters (e.g., [[a, 3, 0.3], [b, 3, 0.3], [c, 3, 0.3]] to an algorithm which will use them as input. This 3-D list forms effectively the entire parameter space that will need to be "searched". Thus you can see why the following combination examples:



[[a, 1, 0.3], [b, 2, 0.3], [c, 2, 0.3]],
[[a, 3, 0.1], [b, 1, 0.3], [c, 2, 0.1]]



Are important, because they serve as a unique of parameters for algorithmic input.



Really grateful for any guidance on this, thanks.







python-3.x python-2.7 list numpy itertools






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 at 6:54









enamoria

606521




606521










asked Nov 23 at 1:23









Ryan

63




63








  • 1




    Welcome to StackOverflow! So, what have you tried?
    – Andreas
    Nov 23 at 1:33










  • what is the output dimension?
    – kevinkayaks
    Nov 23 at 1:45










  • @kevinkayaks, the output dimensions are as follows:
    – Ryan
    Nov 23 at 9:43










  • ` x = [[[a],[0],[0.1]],[[a],[0],[0.1]],[[a],[0],[0.1]]], y = all combinations of above`. Does that make sense? So 3 dimensions, where y equals all the combinations for a row as described above.
    – Ryan
    Nov 23 at 9:49










  • @Andreas I had try to have recursive loops for each list, then using iterools with permutations, but could not get the right output as per above.
    – Ryan
    Nov 23 at 10:11














  • 1




    Welcome to StackOverflow! So, what have you tried?
    – Andreas
    Nov 23 at 1:33










  • what is the output dimension?
    – kevinkayaks
    Nov 23 at 1:45










  • @kevinkayaks, the output dimensions are as follows:
    – Ryan
    Nov 23 at 9:43










  • ` x = [[[a],[0],[0.1]],[[a],[0],[0.1]],[[a],[0],[0.1]]], y = all combinations of above`. Does that make sense? So 3 dimensions, where y equals all the combinations for a row as described above.
    – Ryan
    Nov 23 at 9:49










  • @Andreas I had try to have recursive loops for each list, then using iterools with permutations, but could not get the right output as per above.
    – Ryan
    Nov 23 at 10:11








1




1




Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 23 at 1:33




Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 23 at 1:33












what is the output dimension?
– kevinkayaks
Nov 23 at 1:45




what is the output dimension?
– kevinkayaks
Nov 23 at 1:45












@kevinkayaks, the output dimensions are as follows:
– Ryan
Nov 23 at 9:43




@kevinkayaks, the output dimensions are as follows:
– Ryan
Nov 23 at 9:43












` x = [[[a],[0],[0.1]],[[a],[0],[0.1]],[[a],[0],[0.1]]], y = all combinations of above`. Does that make sense? So 3 dimensions, where y equals all the combinations for a row as described above.
– Ryan
Nov 23 at 9:49




` x = [[[a],[0],[0.1]],[[a],[0],[0.1]],[[a],[0],[0.1]]], y = all combinations of above`. Does that make sense? So 3 dimensions, where y equals all the combinations for a row as described above.
– Ryan
Nov 23 at 9:49












@Andreas I had try to have recursive loops for each list, then using iterools with permutations, but could not get the right output as per above.
– Ryan
Nov 23 at 10:11




@Andreas I had try to have recursive loops for each list, then using iterools with permutations, but could not get the right output as per above.
– Ryan
Nov 23 at 10:11












2 Answers
2






active

oldest

votes


















1














A generator seems a good approach, to avoid cluttering up the memory.



import itertools as it
bc=list(it.product(b,c))
#[(1, 0.1), (1, 0.2), (1, 0.3), (2, 0.1), (2, 0.2), (2, 0.3), (3, 0.1), (3, 0.2), (3, 0.3)]
res = ([[u,*v] for u,v in zip(a,bc3)] for bc3 in it.product(*[bc]*3))


you can then scan your space with :



 for list_of_list in res : 
#compute list_of_list


First values :



In [49]: next(res) 
Out[49]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.1]]
In [50]: next(res)
Out[50]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.2]]


You can obtain an array by arr = np.array(list(res),dtype=object) . its shape is (729,3,3).






share|improve this answer























  • @Ryan this is the best answer. Thanks B.M., I learned from this.
    – kevinkayaks
    Nov 23 at 23:35










  • @kevinkayaks terms of stackoverflow etiquette is it acceptable to change the answer to this if it is better than a previously posted answer?
    – Ryan
    Nov 24 at 1:11










  • @B. M. That works perfectly, and much more elegant. Thank you.
    – Ryan
    Nov 24 at 1:12










  • @Ryan people do this. It's not a huge deal as far as I know. Presumably it will help people who are searching for an approach in the future to select the best one.
    – kevinkayaks
    Nov 24 at 4:27



















-1














import numpy as np 
import itertools as it
a = ['a', 'b', 'c']
b = [1, 2, 3]
c = [0.1, 0.2, 0.3]
l = np.array(np.meshgrid(a,b,c)).T
l = l.reshape(l.size//3,3)
subs = [[list(x) for x in l if x[0]==val] for val in a]
list(list(x) for x in it.product(*subs))


Try this one. It generalizes to a,b,c,d,... in an obvious way.



That said, you're going to run out of memory very quickly.






share|improve this answer























  • I don't think this exactly what I am looking for. For example, each X ("row") dimension should consist of the following: [[a, 1, 0.1],[b, 1, 0.1][c, 1, 0.2]], with all subsequent rows containing all of combinations in an iterative way for each sublist. Such that list = [[,,],[[,,]] and each sublist iterates through every combination possible between the possible values in list b and c. In the output, each row should consist of these combinations for values a, b, c in list a. I hope I haven't been too confusing!
    – Ryan
    Nov 23 at 9:55










  • have you tried itertools.combinations?
    – kevinkayaks
    Nov 23 at 9:58










  • Yes I tried itertools.combinations and itertools.permutations, thanks for the above. Yes, memory is a problem, although for the time being I am ignoring this problem for the sake of experimentation. As @Red Cricket answered first (and I didn't ask explicitly for the most elegant solution), I have to accept his answer, but will upvote this one (it will accept my vote, but not post it visibly because of my uber newbie status). Thanks again.
    – Ryan
    Nov 23 at 16:46












  • For context regarding the memory problem. This list is to generate an action space containing combinations of parameters for reinforcement learning. So, ideally in the case of millions of combination as a, b, c, d etc., scales the RL environment would obviously need lots of memory,.
    – Ryan
    Nov 23 at 17:05











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439656%2fcreate-lists-with-3-levels-containing-every-combination-of-sub-lists-values%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














A generator seems a good approach, to avoid cluttering up the memory.



import itertools as it
bc=list(it.product(b,c))
#[(1, 0.1), (1, 0.2), (1, 0.3), (2, 0.1), (2, 0.2), (2, 0.3), (3, 0.1), (3, 0.2), (3, 0.3)]
res = ([[u,*v] for u,v in zip(a,bc3)] for bc3 in it.product(*[bc]*3))


you can then scan your space with :



 for list_of_list in res : 
#compute list_of_list


First values :



In [49]: next(res) 
Out[49]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.1]]
In [50]: next(res)
Out[50]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.2]]


You can obtain an array by arr = np.array(list(res),dtype=object) . its shape is (729,3,3).






share|improve this answer























  • @Ryan this is the best answer. Thanks B.M., I learned from this.
    – kevinkayaks
    Nov 23 at 23:35










  • @kevinkayaks terms of stackoverflow etiquette is it acceptable to change the answer to this if it is better than a previously posted answer?
    – Ryan
    Nov 24 at 1:11










  • @B. M. That works perfectly, and much more elegant. Thank you.
    – Ryan
    Nov 24 at 1:12










  • @Ryan people do this. It's not a huge deal as far as I know. Presumably it will help people who are searching for an approach in the future to select the best one.
    – kevinkayaks
    Nov 24 at 4:27
















1














A generator seems a good approach, to avoid cluttering up the memory.



import itertools as it
bc=list(it.product(b,c))
#[(1, 0.1), (1, 0.2), (1, 0.3), (2, 0.1), (2, 0.2), (2, 0.3), (3, 0.1), (3, 0.2), (3, 0.3)]
res = ([[u,*v] for u,v in zip(a,bc3)] for bc3 in it.product(*[bc]*3))


you can then scan your space with :



 for list_of_list in res : 
#compute list_of_list


First values :



In [49]: next(res) 
Out[49]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.1]]
In [50]: next(res)
Out[50]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.2]]


You can obtain an array by arr = np.array(list(res),dtype=object) . its shape is (729,3,3).






share|improve this answer























  • @Ryan this is the best answer. Thanks B.M., I learned from this.
    – kevinkayaks
    Nov 23 at 23:35










  • @kevinkayaks terms of stackoverflow etiquette is it acceptable to change the answer to this if it is better than a previously posted answer?
    – Ryan
    Nov 24 at 1:11










  • @B. M. That works perfectly, and much more elegant. Thank you.
    – Ryan
    Nov 24 at 1:12










  • @Ryan people do this. It's not a huge deal as far as I know. Presumably it will help people who are searching for an approach in the future to select the best one.
    – kevinkayaks
    Nov 24 at 4:27














1












1








1






A generator seems a good approach, to avoid cluttering up the memory.



import itertools as it
bc=list(it.product(b,c))
#[(1, 0.1), (1, 0.2), (1, 0.3), (2, 0.1), (2, 0.2), (2, 0.3), (3, 0.1), (3, 0.2), (3, 0.3)]
res = ([[u,*v] for u,v in zip(a,bc3)] for bc3 in it.product(*[bc]*3))


you can then scan your space with :



 for list_of_list in res : 
#compute list_of_list


First values :



In [49]: next(res) 
Out[49]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.1]]
In [50]: next(res)
Out[50]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.2]]


You can obtain an array by arr = np.array(list(res),dtype=object) . its shape is (729,3,3).






share|improve this answer














A generator seems a good approach, to avoid cluttering up the memory.



import itertools as it
bc=list(it.product(b,c))
#[(1, 0.1), (1, 0.2), (1, 0.3), (2, 0.1), (2, 0.2), (2, 0.3), (3, 0.1), (3, 0.2), (3, 0.3)]
res = ([[u,*v] for u,v in zip(a,bc3)] for bc3 in it.product(*[bc]*3))


you can then scan your space with :



 for list_of_list in res : 
#compute list_of_list


First values :



In [49]: next(res) 
Out[49]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.1]]
In [50]: next(res)
Out[50]: [['a', 1, 0.1], ['b', 1, 0.1], ['c', 1, 0.2]]


You can obtain an array by arr = np.array(list(res),dtype=object) . its shape is (729,3,3).







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 at 17:20

























answered Nov 23 at 17:10









B. M.

12.8k11934




12.8k11934












  • @Ryan this is the best answer. Thanks B.M., I learned from this.
    – kevinkayaks
    Nov 23 at 23:35










  • @kevinkayaks terms of stackoverflow etiquette is it acceptable to change the answer to this if it is better than a previously posted answer?
    – Ryan
    Nov 24 at 1:11










  • @B. M. That works perfectly, and much more elegant. Thank you.
    – Ryan
    Nov 24 at 1:12










  • @Ryan people do this. It's not a huge deal as far as I know. Presumably it will help people who are searching for an approach in the future to select the best one.
    – kevinkayaks
    Nov 24 at 4:27


















  • @Ryan this is the best answer. Thanks B.M., I learned from this.
    – kevinkayaks
    Nov 23 at 23:35










  • @kevinkayaks terms of stackoverflow etiquette is it acceptable to change the answer to this if it is better than a previously posted answer?
    – Ryan
    Nov 24 at 1:11










  • @B. M. That works perfectly, and much more elegant. Thank you.
    – Ryan
    Nov 24 at 1:12










  • @Ryan people do this. It's not a huge deal as far as I know. Presumably it will help people who are searching for an approach in the future to select the best one.
    – kevinkayaks
    Nov 24 at 4:27
















@Ryan this is the best answer. Thanks B.M., I learned from this.
– kevinkayaks
Nov 23 at 23:35




@Ryan this is the best answer. Thanks B.M., I learned from this.
– kevinkayaks
Nov 23 at 23:35












@kevinkayaks terms of stackoverflow etiquette is it acceptable to change the answer to this if it is better than a previously posted answer?
– Ryan
Nov 24 at 1:11




@kevinkayaks terms of stackoverflow etiquette is it acceptable to change the answer to this if it is better than a previously posted answer?
– Ryan
Nov 24 at 1:11












@B. M. That works perfectly, and much more elegant. Thank you.
– Ryan
Nov 24 at 1:12




@B. M. That works perfectly, and much more elegant. Thank you.
– Ryan
Nov 24 at 1:12












@Ryan people do this. It's not a huge deal as far as I know. Presumably it will help people who are searching for an approach in the future to select the best one.
– kevinkayaks
Nov 24 at 4:27




@Ryan people do this. It's not a huge deal as far as I know. Presumably it will help people who are searching for an approach in the future to select the best one.
– kevinkayaks
Nov 24 at 4:27













-1














import numpy as np 
import itertools as it
a = ['a', 'b', 'c']
b = [1, 2, 3]
c = [0.1, 0.2, 0.3]
l = np.array(np.meshgrid(a,b,c)).T
l = l.reshape(l.size//3,3)
subs = [[list(x) for x in l if x[0]==val] for val in a]
list(list(x) for x in it.product(*subs))


Try this one. It generalizes to a,b,c,d,... in an obvious way.



That said, you're going to run out of memory very quickly.






share|improve this answer























  • I don't think this exactly what I am looking for. For example, each X ("row") dimension should consist of the following: [[a, 1, 0.1],[b, 1, 0.1][c, 1, 0.2]], with all subsequent rows containing all of combinations in an iterative way for each sublist. Such that list = [[,,],[[,,]] and each sublist iterates through every combination possible between the possible values in list b and c. In the output, each row should consist of these combinations for values a, b, c in list a. I hope I haven't been too confusing!
    – Ryan
    Nov 23 at 9:55










  • have you tried itertools.combinations?
    – kevinkayaks
    Nov 23 at 9:58










  • Yes I tried itertools.combinations and itertools.permutations, thanks for the above. Yes, memory is a problem, although for the time being I am ignoring this problem for the sake of experimentation. As @Red Cricket answered first (and I didn't ask explicitly for the most elegant solution), I have to accept his answer, but will upvote this one (it will accept my vote, but not post it visibly because of my uber newbie status). Thanks again.
    – Ryan
    Nov 23 at 16:46












  • For context regarding the memory problem. This list is to generate an action space containing combinations of parameters for reinforcement learning. So, ideally in the case of millions of combination as a, b, c, d etc., scales the RL environment would obviously need lots of memory,.
    – Ryan
    Nov 23 at 17:05
















-1














import numpy as np 
import itertools as it
a = ['a', 'b', 'c']
b = [1, 2, 3]
c = [0.1, 0.2, 0.3]
l = np.array(np.meshgrid(a,b,c)).T
l = l.reshape(l.size//3,3)
subs = [[list(x) for x in l if x[0]==val] for val in a]
list(list(x) for x in it.product(*subs))


Try this one. It generalizes to a,b,c,d,... in an obvious way.



That said, you're going to run out of memory very quickly.






share|improve this answer























  • I don't think this exactly what I am looking for. For example, each X ("row") dimension should consist of the following: [[a, 1, 0.1],[b, 1, 0.1][c, 1, 0.2]], with all subsequent rows containing all of combinations in an iterative way for each sublist. Such that list = [[,,],[[,,]] and each sublist iterates through every combination possible between the possible values in list b and c. In the output, each row should consist of these combinations for values a, b, c in list a. I hope I haven't been too confusing!
    – Ryan
    Nov 23 at 9:55










  • have you tried itertools.combinations?
    – kevinkayaks
    Nov 23 at 9:58










  • Yes I tried itertools.combinations and itertools.permutations, thanks for the above. Yes, memory is a problem, although for the time being I am ignoring this problem for the sake of experimentation. As @Red Cricket answered first (and I didn't ask explicitly for the most elegant solution), I have to accept his answer, but will upvote this one (it will accept my vote, but not post it visibly because of my uber newbie status). Thanks again.
    – Ryan
    Nov 23 at 16:46












  • For context regarding the memory problem. This list is to generate an action space containing combinations of parameters for reinforcement learning. So, ideally in the case of millions of combination as a, b, c, d etc., scales the RL environment would obviously need lots of memory,.
    – Ryan
    Nov 23 at 17:05














-1












-1








-1






import numpy as np 
import itertools as it
a = ['a', 'b', 'c']
b = [1, 2, 3]
c = [0.1, 0.2, 0.3]
l = np.array(np.meshgrid(a,b,c)).T
l = l.reshape(l.size//3,3)
subs = [[list(x) for x in l if x[0]==val] for val in a]
list(list(x) for x in it.product(*subs))


Try this one. It generalizes to a,b,c,d,... in an obvious way.



That said, you're going to run out of memory very quickly.






share|improve this answer














import numpy as np 
import itertools as it
a = ['a', 'b', 'c']
b = [1, 2, 3]
c = [0.1, 0.2, 0.3]
l = np.array(np.meshgrid(a,b,c)).T
l = l.reshape(l.size//3,3)
subs = [[list(x) for x in l if x[0]==val] for val in a]
list(list(x) for x in it.product(*subs))


Try this one. It generalizes to a,b,c,d,... in an obvious way.



That said, you're going to run out of memory very quickly.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 at 10:33

























answered Nov 23 at 1:49









kevinkayaks

1,214417




1,214417












  • I don't think this exactly what I am looking for. For example, each X ("row") dimension should consist of the following: [[a, 1, 0.1],[b, 1, 0.1][c, 1, 0.2]], with all subsequent rows containing all of combinations in an iterative way for each sublist. Such that list = [[,,],[[,,]] and each sublist iterates through every combination possible between the possible values in list b and c. In the output, each row should consist of these combinations for values a, b, c in list a. I hope I haven't been too confusing!
    – Ryan
    Nov 23 at 9:55










  • have you tried itertools.combinations?
    – kevinkayaks
    Nov 23 at 9:58










  • Yes I tried itertools.combinations and itertools.permutations, thanks for the above. Yes, memory is a problem, although for the time being I am ignoring this problem for the sake of experimentation. As @Red Cricket answered first (and I didn't ask explicitly for the most elegant solution), I have to accept his answer, but will upvote this one (it will accept my vote, but not post it visibly because of my uber newbie status). Thanks again.
    – Ryan
    Nov 23 at 16:46












  • For context regarding the memory problem. This list is to generate an action space containing combinations of parameters for reinforcement learning. So, ideally in the case of millions of combination as a, b, c, d etc., scales the RL environment would obviously need lots of memory,.
    – Ryan
    Nov 23 at 17:05


















  • I don't think this exactly what I am looking for. For example, each X ("row") dimension should consist of the following: [[a, 1, 0.1],[b, 1, 0.1][c, 1, 0.2]], with all subsequent rows containing all of combinations in an iterative way for each sublist. Such that list = [[,,],[[,,]] and each sublist iterates through every combination possible between the possible values in list b and c. In the output, each row should consist of these combinations for values a, b, c in list a. I hope I haven't been too confusing!
    – Ryan
    Nov 23 at 9:55










  • have you tried itertools.combinations?
    – kevinkayaks
    Nov 23 at 9:58










  • Yes I tried itertools.combinations and itertools.permutations, thanks for the above. Yes, memory is a problem, although for the time being I am ignoring this problem for the sake of experimentation. As @Red Cricket answered first (and I didn't ask explicitly for the most elegant solution), I have to accept his answer, but will upvote this one (it will accept my vote, but not post it visibly because of my uber newbie status). Thanks again.
    – Ryan
    Nov 23 at 16:46












  • For context regarding the memory problem. This list is to generate an action space containing combinations of parameters for reinforcement learning. So, ideally in the case of millions of combination as a, b, c, d etc., scales the RL environment would obviously need lots of memory,.
    – Ryan
    Nov 23 at 17:05
















I don't think this exactly what I am looking for. For example, each X ("row") dimension should consist of the following: [[a, 1, 0.1],[b, 1, 0.1][c, 1, 0.2]], with all subsequent rows containing all of combinations in an iterative way for each sublist. Such that list = [[,,],[[,,]] and each sublist iterates through every combination possible between the possible values in list b and c. In the output, each row should consist of these combinations for values a, b, c in list a. I hope I haven't been too confusing!
– Ryan
Nov 23 at 9:55




I don't think this exactly what I am looking for. For example, each X ("row") dimension should consist of the following: [[a, 1, 0.1],[b, 1, 0.1][c, 1, 0.2]], with all subsequent rows containing all of combinations in an iterative way for each sublist. Such that list = [[,,],[[,,]] and each sublist iterates through every combination possible between the possible values in list b and c. In the output, each row should consist of these combinations for values a, b, c in list a. I hope I haven't been too confusing!
– Ryan
Nov 23 at 9:55












have you tried itertools.combinations?
– kevinkayaks
Nov 23 at 9:58




have you tried itertools.combinations?
– kevinkayaks
Nov 23 at 9:58












Yes I tried itertools.combinations and itertools.permutations, thanks for the above. Yes, memory is a problem, although for the time being I am ignoring this problem for the sake of experimentation. As @Red Cricket answered first (and I didn't ask explicitly for the most elegant solution), I have to accept his answer, but will upvote this one (it will accept my vote, but not post it visibly because of my uber newbie status). Thanks again.
– Ryan
Nov 23 at 16:46






Yes I tried itertools.combinations and itertools.permutations, thanks for the above. Yes, memory is a problem, although for the time being I am ignoring this problem for the sake of experimentation. As @Red Cricket answered first (and I didn't ask explicitly for the most elegant solution), I have to accept his answer, but will upvote this one (it will accept my vote, but not post it visibly because of my uber newbie status). Thanks again.
– Ryan
Nov 23 at 16:46














For context regarding the memory problem. This list is to generate an action space containing combinations of parameters for reinforcement learning. So, ideally in the case of millions of combination as a, b, c, d etc., scales the RL environment would obviously need lots of memory,.
– Ryan
Nov 23 at 17:05




For context regarding the memory problem. This list is to generate an action space containing combinations of parameters for reinforcement learning. So, ideally in the case of millions of combination as a, b, c, d etc., scales the RL environment would obviously need lots of memory,.
– Ryan
Nov 23 at 17:05


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439656%2fcreate-lists-with-3-levels-containing-every-combination-of-sub-lists-values%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks