Jack Hopkins
Jack Hopkins

Reputation: 73

Torch 'Gather' Issue

I have two tensors as follows:

Normalised Tensor :
1
10
94
[torch.LongStorage of size 3]

and

Batch :
1
10
[torch.LongStorage of size 2]

I would like to use 'Batch' to select indices in the 3 dimension of 'Normalised Tensor'. So far I have used gather as follows:

normalised:long():gather(1, batch:long())

Unfortunately it's returning this error. "bad argument #1 to 'gather' (Input tensor must have same dimensions as output"

Any help would be much appreciated! Thanks

Upvotes: 0

Views: 675

Answers (1)

Dimitry
Dimitry

Reputation: 2348

Answer is based on assuming the following: you have a three dimensional tensor of sizes x,y,z and you want a three dimensional tensor of size x,y,10 where the x,y slices are chosen based on indices listed in another tensor of size 1,10.

I, personally, have spent much time pondering what would be the possible use of the gather method. Only conclusion I've come to is: it not the problem described above.

The described problem is solvable by use of the index function:

local slice = normalised:gather(3, batch[1]:long())

Upvotes: 0

Related Questions