김영석
김영석

Reputation: 11

how to add tensor size pytorch

I have a problem while working on PyTorch.

I'm trying to increase tensor size from [1,97,1] to [1,97,2]. How can I add "1" in tensor size?

Upvotes: 0

Views: 77

Answers (1)

Dishin H Goyani
Dishin H Goyani

Reputation: 7723

Use pad

import torch.nn.functional as F
a = torch.empty((1,97,1))

a = F.pad(input=a, pad=(0,1))     # pad = (padding_left,padding_right)

print(a.shape)
>>> torch.Size([1, 97, 2])

it will pad 0 constant by default at right sight.

Upvotes: 1

Related Questions