Pytorch reshape tensor dimension

前端 未结 10 549
忘掉有多难
忘掉有多难 2021-02-03 17:56

For example, I have 1D vector with dimension (5). I would like to reshape it into 2D matrix (1,5).

Here is how I do it with numpy

>>> import num         


        
10条回答
  •  情话喂你
    2021-02-03 18:07

    import torch
    t = torch.ones((2, 3, 4))
    t.size()
    
    >>torch.Size([2, 3, 4])
    
    a = t.view(-1,t.size()[1]*t.size()[2])
    a.size()
    
    >>torch.Size([2, 12])
    

提交回复
热议问题