Problem with gather function

i have tow tensors
ind with size = (2, 261234, 1)
g = with size = (2, 783456, 1)
i wante to gather tem with the gather function, and put the result in g
whene i write g = g.gather(1, ind) the folowing error apeer:
RuntimeError: Expected object of type torch.LongTensor but found type torch.FloatTensor for argument #3 ‘index’
whene i try to change the type of ind by ind.type(tornch.long), i got this error;

RuntimeError: Invalid index in gather at /opt/conda/conda-bld/pytorch_1524584710464/work/aten/src/TH/generic/THTensorMath.c:600
any one can help me?


This error means that the indices contained in ind are out of bound for the indexing you’re trying to do.
Have you checked these values?

how can the indices be out of bounds?
the shapes of the tensors are correct to do gather, and values in ind are the result of a series of convolutions and max pooling, i cant change theme.

If your dimension is of size 783456, then the indices have to be in [0, 783455]`.
Just like if you have a python list with 10 elements, you can’t access the 20th.

you are right, i had make some modifications, wich change the nember of inputs, so the indices must be changed also
thank you very mutch. i have found the solution