Solved by learner47 in post #2 
              
              
                I found out that unsqueezing and squeezing are not required and can be combined. 
a = torch.from_numpy(np.array([1, 2, 3])[None, :, None])  # (1, 3, 1)
b = torch.roll(a, shifts=-1, dims=1)
b[:, -1, :] = 4