# How to resize a tensor in a particular order?

Let’s say I have a 1 x 3n tensor [a, b, c, d, e, f…]. I want to resize it into a 3 x n tensor, in the particular order [[a, d,…], [b, e,…], [c, f…]]. In other words, the order in which the numbers are populated are different than from just applying resize. How can this be done? Thanks!

Just take the tensor and do
`tensor=tensor.reshape(3,n).T`

``````In [1]: import torch

In [2]: n=10

In [3]: w=torch.arange(3*n)

In [4]: w
Out[4]:
tensor([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29])

In [5]: q=w.reshape(3,n)

In [6]: q
Out[6]:
tensor([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29]])

In [7]: q=w.reshape(3,n).T

In [8]: q[0]
Out[8]: tensor([ 0, 10, 20])
``````

By this logic you can do any reshaping if the dimensions match. Because you are taking 1 out of m elements. Just replace 3 by any other number which matches and thats all.
In the worst case your dimensions will mismatch, so you will have to pad manually the last values and fill the last row.