Hi,
I think this question is very similar to this post 2 (which explains how to access an 4-D tensor through 3-D index), but I still can’t figure it out.
I want to access an 4-D tensor through 2-D index like following:
dim1 = 3
dim2 = 4
dim3 = 5
dim4 = 10
source = torch.randn((dim1,dim2,dim3,dim4))
index = torch.randint(dim3, (dim1, dim2))
ret =  torch.FloatTensor(dim1, dim2, dim3)

for i in range(dim1):
    for j in range(dim2):
        ret[i,j,:] = source[i, j, index[i,j], :]