It seems that when using :
and ...
in this context they yield the same result. However, it seems when using :
, and ...
in terms of adding a new dim to a Tensor they give different results.
>>> M=torch.randn(3,4)
>>> M
tensor([[-1.1915, 1.3102, 2.4116, -0.6022],
[-1.4025, -0.0796, -0.6342, -1.5389],
[-0.3399, -0.1049, 0.0192, 0.0186]])
#grab last column
>>> M[..., -1]
tensor([-0.6022, -1.5389, 0.0186])
>>> M[:, -1]
tensor([-0.6022, -1.5389, 0.0186])
#adding new dim
#shape torch.Size([3, 1, 4])
>>> M[:, None]
tensor([[[-1.1915, 1.3102, 2.4116, -0.6022]],
[[-1.4025, -0.0796, -0.6342, -1.5389]],
[[-0.3399, -0.1049, 0.0192, 0.0186]]])
#shape torch.Size([3, 4, 1])
>>> M[..., None]
tensor([[[-1.1915],
[ 1.3102],
[ 2.4116],
[-0.6022]],
[[-1.4025],
[-0.0796],
[-0.6342],
[-1.5389]],
[[-0.3399],
[-0.1049],
[ 0.0192],
[ 0.0186]]])
>>>
So, in your cases they are the same? but in other cases they’ll give different behaviour!