Wrap two tensors in pytorch to get size of new tensor as 2
I have two tensors say x and y:

x has shape: [21314, 3, 128, 128]
y has shape: [21314]

Can I get new tensor of shape : [ [21314, 3, 128, 128], [21314] ], basically of shape 2

I believe it's not possible, if you require to save it as a tensor object. Of course, you can use a list or a tuple for this case, but I guess that was not what you meant.

First, a tensor is simply a generalization of a matrix for n dimentions instead of two. But let's simplify this for a matrix for now, for example 4x3. The first dimention is of size 4, that means 4 entries. A second dimention of 3 means that each of the 4 first dimention entries will have exactly (and not less then) 3 entries. That is, you must have full list of 3 elements in each nested list. In this simple example, note that you cannot have a matrix like that one:

[[1,2,3]

 [1,2]

 [1]    ]


while this is a nested list it's not a matrix and also not a tensor of 2d. What i'm trying to say is that the shape your requested - [ [21314, 3, 128, 128], [21314] ] - is actually not a tensor.

But, you could have think of it as a tensor of size two, with data type of tensor in each entry (what you probably ment when asking the question). Though this is not possible since tensors in pytorch holds only numbers of types: float32, float64, float16, uint8, int8, int16, int32, int64, bool.

Nevertheless, in most cases you can achieve what you need with assigning two tensors to a list or tuple.
