How can I insert a row into a FloatTensor?

Such as:

I have a FloatTensor type data which size of [46,300], and I want to insert a row into this tensor in position of 20, how can I achieve this operatoin??

Look forward to your reply!!!:smile:

If I understand correctly if x.size() is [46, 300] you want to increase it to [47, 300].
if so, here is an example of how to do it, insert at position 20 a row with 300 items:

import torch
x = torch.Tensor(46, 300)
print(x.size()) #torch.Size([46, 300])

first_half = x[0:20, :]
second_half = x[20:, :]
new_row = torch.Tensor(1, 300)
new_x =, new_row, second_half)

print(new_x.size()) #torch.Size([47, 300])