reshaping a tensor with padding in pytorch

前端 未结 4 753
不思量自难忘°
不思量自难忘° 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:21

    A module that might be clearer and more suitable for this question is torch.nn.ConstantPad1d e.g.

    import torch
    from torch import nn
    
    x = torch.ones(30, 35, 49)
    padded = nn.ConstantPad1d((0, 512 - 49), 0)(x)
    

提交回复
热议问题