I am trying to better understand this syntax in Lua when using Torch:
local ten = torch.Tensor{{1,2,3},{4,5,6},{7,8,9}}
for i=1,(#ten)[2] do
print(ten[i][{{2}}])
end
Specifically the line
print(ten[i][{{2}}])
When I run the code, it prints
2
[torch.DoubleTensor of size 1]
5
[torch.DoubleTensor of size 1]
8
[torch.DoubleTensor of size 1]
I am familiar with table literals and their basic syntax, but what is the purpose of wrapping the '2' in double curly-braces, and how does it work in the engine?
The following answer was posted on GitHub when I asked the same question: https://github.com/torch/torch7/issues/501#issuecomment-171290546
Have a look at this part of the documentation.
For more information, have a look at select and narrow. One last note, the doc for select is not precisely correct, as it's possible to do a select on a 1D tensor, and the output is a number.