Pytorch reshape tensor dimension

前端 未结 10 649
忘掉有多难
忘掉有多难 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:24

    or you can use this, the '-1' means you don't have to specify the number of the elements.

    In [3]: a.view(1,-1)
    Out[3]:
    
     1  2  3  4  5
    [torch.FloatTensor of size 1x5]
    

提交回复
热议问题