我正在使用torch7生成異或門數據集。但是,當我打印數據集,我看到數據是錯誤的,但我找不到錯誤。代碼似乎沒有錯。但我是新來的火炬,所以錯誤可能會發生。torch7的意外行爲
所以,這裏是我的代碼
input = torch.Tensor (4,2)
input:random(0,1)
output = torch.Tensor(1)
dataset={};
function dataset:size() return 4 end
for i=1,dataset:size() do
if input[i][1]==input[i][2] then
output[1] = 0
else
output[1] = 1
end
print("original")
print(input[i][1].." "..input[i][2].." "..output[1]) -- the values that are going to dataset
dataset[i] = {input[i], output}
print("dataset")
print(dataset[i][1][1].." "..dataset[i][1][2].." "..dataset[i][2][1]) -- for double checking i read from dataset again
end
print("Why dataset is different now?")
for i=1,4 do
print(dataset[i][1][1].." "..dataset[i][1][2].." "..dataset[i][2][1]) -- So, why this is different?
end
正如你所看到的,我印正在插入dataset
列表和雙重檢查我從dataset
再次讀取值。
最後我從dataset
檢查完全插入後。數據集在某種程度上是不同的。我跑了幾次。每一次都不一樣。就像是粘在1或0
因此,這裏是我的輸出
original
1 0 1
dataset
1 0 1
original
0 0 0
dataset
0 0 0
original
1 1 0
dataset
1 1 0
original
0 0 0
dataset
0 0 0
Why dataset is different now?
1 0 0
0 0 0
1 1 0
0 0 0
正如你所看到的,格式是這樣
input input output
我原來印刷的時候,我讀從輸入[i]和輸出。
我在插入數據集後從數據集中讀取數據集。
你也可以看到,當我打印時,第一組值是不同的。它應該是1 0 1.但是它是1 0 0.
我在我的代碼中找不到該錯誤。誰能幫忙?如果問題不明確,請告訴我。
謝謝:)。我明白。這就像蟒蛇吧? –
是的,很像在Python中:) – Vlad