Convert tensor([4,1]) to tensor([4,2]) without changing elements

Hello,

I want to convert tensor([4]) to tensor([4,2]) without changing elements in it.

I have tried using torch.reshape, but it does not work, and gives some error.

I do not want to change the dimension using squeeze or unsqeeze.

My aim is to use BInary Cross Entropy,
And I have target shape tensor([4,1]) and output shape tensor([4,2])

But it says that BCE Loss inputs must be of same shape.

Any help is most appreciated!

Thank you in advanvce. @ptrblck @eqy

If you have a tensor which is 4,1 you can’t magically get a tensor which is 4,2.
One is 4 elements and the other 8.
You should think in the logics behind that. You may want to use random numbers, to tile the tensor…

Reshapes just reorder elements but doesn’t create the. Unsqueeze creates new dimensions but not new elements.