Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 将字符串拆分为火炬张量_String_Split_Lua_Torch - Fatal编程技术网

String 将字符串拆分为火炬张量

String 将字符串拆分为火炬张量,string,split,lua,torch,String,Split,Lua,Torch,我在Lua中有两个字符串: a = '01234' b = '12345' 我想把它们分成几个字符,然后将它们加载到火炬张量中,如下所示: 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 en

我在Lua中有两个字符串:

a = '01234'
b = '12345'
我想把它们分成几个字符,然后将它们加载到火炬张量中,如下所示:

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)}