我在 Lua 中有 2 个字符串:
a = '01234'
b = '12345'
我想将它们分成字符并将它们加载到 Torch 张量中,如下所示:
tens = torch.Tensor{{0, 1, 2, 3, 4}, {1, 2, 3, 4, 5}}
谢谢。
最佳答案
function split(str)
tbl = {}
for c in str:gmatch('.') do
table.insert(tbl, c)
end
return tbl
end
a = '01234'
b = '12345'
tens = torch.Tensor{split(a), split(b)}
关于string - 将字符串字符拆分为 Torch 张量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34759914/