Dynamically extend the tensor

I have two tensors

t1 = torch.tensor([ 1,  9, 12,  5, 24])
t2 = torch.tensor([ 1, 24])

Now, I want to extend the tensor t2 to the same size as t1.

How can I do this without using loops?

hmmm you can do this:
or this

but im not sure what do you mean by extending, because when the size change the values need to change too. so what do you want the elements of t2 to be?

Maybe you can use the repeat function.

Sorry for not being completely clear about my requirement.

I want to extend the tensor t2 to be the same size as t1 where the “extra values that need to be filled in t2” can be some unique number that is currently not in t2. For instance,

t2 = torch.tensor([ 1, 24, 0, 0, 0])

I tried it with


That sort of works but it doesn’t give the flexibility to fill in using our own values.