Search code examples
arraysluatorch

Initializing multi dimensional arrays in lua/torch


I have gone through a few tutorials about "arrays" in lua/torch and all I see is the word tensors. What exactly are they? How can i initialize a 2d "tensor"? I tried torch.Tensor{1,2,3} which gave me

1
2
3

and torch.Tensor{1,2,3;4,5,6} like in octave/MATLAB but this gave me another column vector

1
2
3
4
5
6

How can I get a 2d "tensor" like the following?

1 2 3
4 5 6

Also, I'm using torch to execute my lua files. Is there no other notation for arrays other than "tensors" i.e. is there no other way we can use to represent a matrix in torch?


Solution

  • torch.Tensor{{1, 2, 3}, {4, 5, 6}}
    

    Have a look at this (or that) for more details on tensors.