嵌套字典结构';python中保持相同结构的字典列表的s排列
我有以下JSON/字典结构嵌套字典结构';python中保持相同结构的字典列表的s排列,python,json,dictionary,permutation,Python,Json,Dictionary,Permutation,我有以下JSON/字典结构 { "layers": [{ "type": "fc", "name": "fc1", "nodes": [100, 200], "activation": "relu", "dropout": false }, { "type": "fc", "name": "fc2",
{
"layers": [{
"type": "fc",
"name": "fc1",
"nodes": [100, 200],
"activation": "relu",
"dropout": false
}, {
"type": "fc",
"name": "fc2",
"nodes": 50,
"activation": ["relu", "tanh"],
"dropout": false
}
],
"hyper_parameters": {
"dropout": [0.25, 0.30],
"lr": [0.01, 0.002, 0.5],
"lr_decay": 1,
"epochs": 100,
"epoch_no_imprv": 10,
"batch_size": 100
}
}
我想生成上述结构的所有排列,只要有列表,就保留相同的结构。
所以上面的结构应该生成24个这样的结构的列表。 显示下面的示例4结构
[
{
"layers": [{
"type": "fc",
"name": "fc1",
"nodes": 100,
"activation": "relu",
"dropout": false
}, {
"type": "fc",
"name": "fc2",
"nodes": 50,
"activation": "relu",
"dropout": false
}
],
"hyper_parameters": {
"dropout": 0.25,
"lr": 0.01,
"lr_decay": 1,
"epochs": 100,
"epoch_no_imprv": 10,
"batch_size": 100
}
},
{
"layers": [{
"type": "fc",
"name": "fc1",
"nodes": 200,
"activation": "relu",
"dropout": false
}, {
"type": "fc",
"name": "fc2",
"nodes": 50,
"activation": "relu",
"dropout": false
}
],
"hyper_parameters": {
"dropout": 0.25,
"lr": 0.01,
"lr_decay": 1,
"epochs": 100,
"epoch_no_imprv": 10,
"batch_size": 100
}
},
{
"layers": [{
"type": "fc",
"name": "fc1",
"nodes": 100,
"activation": "relu",
"dropout": false
}, {
"type": "fc",
"name": "fc2",
"nodes": 50,
"activation": "tanh",
"dropout": false
}
],
"hyper_parameters": {
"dropout": 0.25,
"lr": 0.01,
"lr_decay": 1,
"epochs": 100,
"epoch_no_imprv": 10,
"batch_size": 100
}
},
{
"layers": [{
"type": "fc",
"name": "fc1",
"nodes": 200,
"activation": "relu",
"dropout": false
}, {
"type": "fc",
"name": "fc2",
"nodes": 50,
"activation": "tanh",
"dropout": false
}
],
"hyper_parameters": {
"dropout": 0.25,
"lr": 0.01,
"lr_decay": 1,
"epochs": 100,
"epoch_no_imprv": 10,
"batch_size": 100
}
}
]
在这里,下面的键可以有一个列表,但我更喜欢它是否足够通用
节点、激活、退出、lr.
“层”列表可以有任意数量的层
任何其他简化结构都可以实现同样的效果。“上述结构应生成18个此类结构的列表”-也许我遗漏了一些东西,但在您的示例中,它不应该是24而不是18吗?是的!!我的错。在问题中更正。感谢您指出,“上面的结构应该生成18个这样的结构的列表”-也许我遗漏了一些东西,但在您的示例中不是应该是24而不是18吗?是的!!我的错。在问题中更正。谢谢你指出这一点。