【Pytorch】torch.reshape
torch.reshape(input, shape)
返回一个张量,其与input的元素和元素个数相同。
>>> a = torch.arange(4.)
>>> torch.reshape(a, (2, 2))
tensor([[ 0., 1.],
[ 2., 3.]])
>>> b = torch.tensor([[0, 1], [2, 3]])
>>> torch.reshape(b, (-1,))
tensor([ 0, 1, 2, 3])
更详细的请参考官网:torch.reshape — PyTorch 1.12 文档