Sure, let’s say you have a first index tensor i containing indices between 0 and 5 :
Variable containing:
(0 ,.,.) = 
  4  4  3  0
  3  4  2  3
  2  3  1  1
  1  4  3  1
[torch.LongTensor of size 1x4x4]

and a second index tensor j of same size:
Variable containing:
(0 ,.,.) = 
  1  1  1  1
  1  1  1  1
  1  1  1  1
  1  1  1  1
[torch.LongTensor of size 1x4x4]

finally a matrix G of size 5x5 initially set to 0.
G = torch.LongTensor(5,5).zero_()

The indexing would proceed like this, pair each index from tensor i and j and increment the G matrix at each index pair.
G[i,j] += 1

For example for the first row of i and j:
G[1, 4] += 1
G[1, 4] += 1
G[1, 3] += 1
G[1, 0] += 1

The current indexing only increases G[1, 4] by 1 instead of 2.