If I have a tensor:
t1 = torch.Tensor(2, 2)
Is there any way get this data as a Lua table?
There is a dedicated constructor to create a tensor from a table but so far there is no method out-of-the box to convert the other way around.
Of course you can do that manually:
-- This assumes `t1` is a 2-dimensional tensor!
local t2 = {}
for i=1,t1:size(1) do
t2[i] = {}
for j=1,t1:size(2) do
t2[i][j] = t1[i][j]
end
end
--
Update: as of commit 10f3323 there is now a dedicated torch.totable(object)
converter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With