我在Lua中有2个字符串:
a = '01234'
b = '12345'
我想将它们分成几个字符并将它们加载到Torch Tensor中,如下所示:
tens = torch.Tensor{{0, 1, 2, 3, 4}, {1, 2, 3, 4, 5}}
感谢。
答案 0 :(得分:2)
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)}