【Pytorch】torch.reshape函数

【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 文档


版权声明:本文为m0_61729283原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。