Hi Alpha!



 AlphaBetaGamma96:

this seems to be the same as unsqueeze(1).


Autgrad indicates that pytorch is smart enough to convert x[:, None]
to x.unsqueeze (1):
>>> import torch
>>> torch.__version__
'1.9.0'
>>> x = torch.ones (2, 3, requires_grad = True)
>>> x.unsqueeze (1)
tensor([[[1., 1., 1.]],

        [[1., 1., 1.]]], grad_fn=<UnsqueezeBackward0>)
>>> x[:, None]
tensor([[[1., 1., 1.]],

        [[1., 1., 1.]]], grad_fn=<UnsqueezeBackward0>)

But this seems to be something of a special case.  Consider:
>>> x[:, None, :]
tensor([[[1., 1., 1.]],

        [[1., 1., 1.]]], grad_fn=<SliceBackward>)
>>> x[None, :]
tensor([[[1., 1., 1.],
         [1., 1., 1.]]], grad_fn=<SliceBackward>)

Best.
K. Frank