这是我的代码:
trainingSet = {"0,0":0, "1,0":1, "2,0":1, "0,1":0, "1,1":1, "1,2":0, "2,0":0, "2,1":0, "2,2":1}
for k,expectedOutput in trainingSet.iteritems():
print 1
coordinates = k.split(",")
network.layers[0].neurons[0].value = float(coordinates[0])
network.layers[0].neurons[1].value = float(coordinates[1])
output = network.calculateOutput()
Run Code Online (Sandbox Code Playgroud)
输出是:
1
1
1
1
1
1
1
1
# 8 lines
Run Code Online (Sandbox Code Playgroud)
怎么可能?trainingSet词典中有9个项目.输出不应该是:
1
1
1
1
1
1
1
1
1
# 9 lines
Run Code Online (Sandbox Code Playgroud)
Mar*_*ers 12
你有两次关键字"2,0":
... "2,0":1, "0,1":0, "1,1":1, "1,2":0, "2,0":0 ...
^^^ ^^^
Run Code Online (Sandbox Code Playgroud)
字典中的键必须是唯一的.如果您希望使用不同的值多次使用密钥,则需要使用不同的数据结构.您可以使用例如元组列表,或从键到字典值列表的字典.
更有可能的是,我猜你只是混淆了数字而你实际上意味着这样的事情:
trainingSet = {
"0,0" : 0, "1,0" : 1, "2,0" : 1,
"0,1" : 0, "1,1" : 1, "2,1" : 0,
"0,2" : 0, "1,2" : 0, "2,2" : 1
}
Run Code Online (Sandbox Code Playgroud)