Slicing gives incorrect result, if the values are the same

I want to make a slice of a tensor with the same value.

import torch
dist = torch.ones((10, 20), dtype=torch.int32)
print(dist[[1, 2], [3, 4]])

It returns tensor([1, 1], dtype=torch.int32). But it should return tensor([[1, 1], [1, 1]], dtype=torch.int32). How do I make it to return this result?

Hi protoneqt!

I’m not sure exactly what you want or are expecting. But maybe the following
helps answer your question:

>>> torch.__version__
'1.7.1'
>>> dist = torch.arange (30).reshape ((5, 6))
>>> dist
tensor([[ 0,  1,  2,  3,  4,  5],
        [ 6,  7,  8,  9, 10, 11],
        [12, 13, 14, 15, 16, 17],
        [18, 19, 20, 21, 22, 23],
        [24, 25, 26, 27, 28, 29]])
>>> dist[[1, 2], [3, 4]]
tensor([ 9, 16])
>>> dist[1:3, 3:5]
tensor([[ 9, 10],
        [15, 16]])

I would call dist[[1, 2], [3, 4]] indexing and dist[1:3, 3:5] slicing,
but I’m not really sure what the proper terminology is.

Best.

K. Frank