# How to reshape Tensor properly?

Hello, I’am a new to pytorch an python. So… I don’t know how to reshape tensors exactly.

For example, I have a [2, 512, 10, 10] <-- (batch_num, C, H ,W) tensor.
Let’s assume that I apply some channel-wise operations to each cells of the tensor. In this case, the operations applied 200 times (2 * 10 * 10, batch_num * H * W) to the tensor. And the shape of the result is like [200, 512].

In this case, I hope to reshape the result tensor ([200, 512]) to original shape [2, 512, 10, 10].
I think I can reshape the tensor using “view” function easily. However I am worrying that the values of the tensor are mixed. (every cell has to locate original position)

So… Could you tell me how to reshape the tensor properly?

( Sorry, I can’t write English well.)

I think you need to either keep the batch and channel dimension or combine those two, but you shouldn’t combine the batch, height, and width dimensions. So your resulting tensor should be (100, 1024), then you do `tensor.reshape(H, W, batch_num, C).permute(2, 3, 0, 1)`. You’ll also have to pay attention to how you permute the tensor before your operation. Honestly, I would try to have your resulting tensor be of dimensions (1024, 100) or (2, 512, 100) and not the transpose, but it’s not 100% necessary to do so. There really is not enough information here to see exactly what you are doing. If you could provide some code, or mathematical equations, it would be easier to help you.

Thank you. Based on your comment, I will try adjusting my tensor operation.