应用
>>> x = torch.randn(4, 4)
>>> x.size()
torch.Size([4, 4])
>>> y = x.view(16)
>>> y.size()
torch.Size([16])
>>> z = x.view(-1, 8) # the size -1 is inferred from other dimensions
>>> z.size()
torch.Size([2, 8])
API
shape (torch.Size or int...) – the desired size
参数 | 描述 |
---|---|
shape (torch.Size or int…) | the desired size |
参考:
https://pytorch.org/docs/stable/tensors.html#torch.Tensor.view