reshaping a tensor with padding in pytorch

前端 未结 4 759
不思量自难忘°
不思量自难忘° 2021-02-02 10:25

I have a tensor with dimensions (30, 35, 49). I want to reshape it to (30, 35, 512) in order to be able to multiply with another tensor which has also

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 11:20

    import torch.nn.functional as F
    data = torch.ones(4, 4)
    # pad(left, right, top, bottom)
    new_data = F.pad(input=data, pad=(1, 1, 1, 1), mode='constant', value=0)
    print(new_data)
    

提交回复
热议问题