How do I insert a 1D Torch tensor into an existing 2D Torch tensor into a specific row?
I want to insert a 1D Torch tensor into a specific row number into a 2D Torch tensor (Using Pytorch).
The 1D tensor and the 2D tensor will always have the same length, so you can easily visualize this as a table with rows and columns.
The 2D tensor is the existing table and I would like to be able to specify the the row number the 1D tensor (or row) will be inserted.
When I say I'd like to use Pytorch, I don't want to turn anything into a non-Pytorch list and send the computations back and forth over the CPU and GPU. The tensors are all already on my CUDA device and I would like to keep them there for the sake of time.
The 2D tensor three_by_four
tensor([[0.7421, 0.1584, 0.3231, 0.4840],
        [0.4065, 0.7646, 0.9677, 0.4537],
        [0.5226, 0.6216, 0.9420, 0.0605]], device='cuda:1')  

The 1D tensor one_by_three
tensor([[0.3095, 0.8460, 0.2900, 0.9683]], device='cuda:1')

The best I was able to do was get the new row (the 1D tensor) appended to the bottom or top of the 2D tensor with torch.cat depending on the order.
The 1D tensor added to the top.
torch.cat([one_by_three, three_by_four])  

tensor([[0.3095, 0.8460, 0.2900, 0.9683],
        [0.7421, 0.1584, 0.3231, 0.4840],
        [0.4065, 0.7646, 0.9677, 0.4537],
        [0.5226, 0.6216, 0.9420, 0.0605]], device='cuda:1')  

The 1D tensor added to the bottom
torch.cat([three_by_four, one_by_three])  
tensor([[0.7421, 0.1584, 0.3231, 0.4840],
        [0.4065, 0.7646, 0.9677, 0.4537],
        [0.5226, 0.6216, 0.9420, 0.0605],
        [0.3095, 0.8460, 0.2900, 0.9683]], device='cuda:1')  

What I would like, for example, if I could put it in position 1, or 2 in this example.
tensor([[0.7421, 0.1584, 0.3231, 0.4840],
        [0.4065, 0.7646, 0.9677, 0.4537],
        [0.3095, 0.8460, 0.2900, 0.9683]
        [0.5226, 0.6216, 0.9420, 0.0605]], device='cuda:1')  


As of now the best I could find
from torch import tensor, cat
x = tensor([[0.7421, 0.1584, 0.3231, 0.4840],
        [0.4065, 0.7646, 0.9677, 0.4537],
        [0.5226, 0.6216, 0.9420, 0.0605]])
y = tensor([[0.3095, 0.8460, 0.2900, 0.9683]])
cat([x[:1], y, x[1:]])
'''
tensor([[0.7421, 0.1584, 0.3231, 0.4840],
        [0.3095, 0.8460, 0.2900, 0.9683],
        [0.4065, 0.7646, 0.9677, 0.4537],
        [0.5226, 0.6216, 0.9420, 0.0605]])
'''

https://discuss.pytorch.org/t/is-there-a-way-to-insert-a-tensor-into-an-existing-tensor/14642
