How can I trim / remove part of a Tensor to match the shape of another Tensor with PyTorch?
I have 2 tensors:

outputs: torch.Size([4, 27, 161])       pred: torch.Size([4, 30, 161])


I want to cut pred (from the end) so that it'll have the same dimensions as outputs.

What's the best way to do it with PyTorch?

You can use Narrow

e.g:

a = torch.randn(4,30,161)
a.size() # torch.Size([4, 30, 161])
a.narrow(1,0,27).size() # torch.Size([4, 27, 161])

