Hello All,

I have a tensor of size(2, 107136, 7) with 1499904 (2x107136x7) total elements and I want to reshape this into (2, 488, 7 = 2x488x7=6832 elements in total). Does anyone have an idea how to reshape by reducing the number of elements? It generated an error RuntimeError: shape ‘[2, 488, 7]’ is invalid for the input of size 1499904(multiple of sizes). Here is what I did it.

x has a size of (2, 107136, 7) and then I did:

x = torch.reshape(x, (2, 488, 7))

The error is because `(2 x 488 x 7)`

is not equal to `( 2 x 107136 x 7)`

. You can tru slicing

Example

a = a[:,0:488,:]

EDIT : But you will loose some information

You can’t reshape the tensor into an other having unequal elements and slicing is not a way to reshape, you are going to lose a lot of valuable information.