Copy using index method

Hi,

I want to copy a 2x1 shape tensor to 2x2 tensor .

I have the input tensor as given below-

t1 = 
tensor([[-1, -1],
              [-1, -1]])

I have to tensor like following

t2 = 
tensor([[12],
             [15]])

I want to copy t2 into t1 it and the output should be like this

t3 = 
tensor([[-1, 12],
              [-1, 15]])

Similarly I have another tensor like this -

x1 =  

tensor([[4, 5],
              [10, 11]])

using copy method I have to copy x1 into x2 which have the shape [5, 3, 2, 1] above tensor in the following tensor

x2[0][0] =  
tensor([[-1],
             [-1]])

and output should be in the shape [5, 3, 2, 2]

x3[0][0] = 
tensor([[4, 5],
              [10, 11]])

Please help me out.

Thanks

Your first use case should work using indexing:

t1[:, 1] = t2.squeeze()

For the second use case you would need to expand the shape of x1:

x2 = x2.repeat(1, 1, 1, 2)
x2[0, 0] = x1

Thank you very much. It worked for me.