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?
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])
If you have the fix number of dimensions of the two tensors, you can try this:
a = torch.randn(3, 5)
b = torch.zeros(3, 2)
b_h, b_w = b.shape
c = a[:b_h, :b_w] # torch.Size([3, 2])
The c has the same shape as b but same values from a.