torch.Tensor.view (Python method, in torch.Tensor)

返回具有相同数据但大小不同的新张量。
返回的张量共享相同的数据,必须具有相同数量的元素,但可能有不同的大小。

Example

>>> 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])

 

posted @ 2017-12-05 14:48  深度学习1  阅读(2782)  评论(0编辑  收藏  举报