arrays - Create a 2D list with variable length [torch] -


i want create 2d list can have elements of variable lengths inside, example, if have 10x10 list in matlab, can define with:

z = cell(10,10) 

and start assigning elements doing this:

z{2}{3} = ones(3,1) z{1}{1} = zeros(100,1) z{1}{2} = [] z{1}{3} = randn(20,1) ... 

what optimal way define such empty 2d list in torch? moreover, there way exploit tensor structure this?

in python, can along define empty 10x10 2d list:

z = [[none j in range(10)] in range(10)] 

my best guess torch doing like

z = torch.tensor(10,10)  i=1,10   j=1,10     z[{{i},{j}}] = torch.tensor()   end end 

but, not work, , defining tensor inside tensor seems bad idea ...

this follow question asked here (however in link asked in python): create 2d lists in python variable length indexed vectors

from documentation i've read, tensors support primitive numeric data types. won't able use tensor intended usage. leverage tables.

local function makematrix(initialval, ...)     local isfunc = type(initialval) == "function"     local dimtable = {...}     local function helper(depth)         if depth == 0             return isfunc , initialval() or initialval         else             local plane = {}             = 1, dimtable[depth]                 plane[i] = helper(depth-1)             end             return plane         end     end     return helper(#dimtable) end  p = makematrix(0, 2, 3, 5) -- makes 3d matrix of size 2x3x5 elements initialized 0  makematrix(torch.tensor, m ,n) 

Comments