The elements in the reshaped matrix will always be orderded column-wise. For example, consider the following code:

using LinearAlgra 
C = [1,2,3,4,5,6]
reshape(C, (2,3))

Output:

2×3 Matrix{Int64}:
 1  3  5
 2  4  6

Notice that number 2 is placed in the first column of the second row, instead of the second column of the first row.

Suppose that we want to create a 2-by-3 matrix where the first row is initially filled and the second row is filled afterwards. We can accomplish this by using permutedims function.

permutedims(reshape(C, (3,2)), (2,1))

What above code does is first reshape matrix C into three-by-two matrix.

reshape(C, (3,2))
3×2 Matrix{Int64}:
 1  4
 2  5
 3  6

Then, permutedims alters the matrix’s dimensions so that the first dimension of the new matrix corresponds to the second dimension of reshape(C, (3,2)), and the second dimension of the new matrix corresponds to the first dimension of reshape(C, (3,2)). This effectively takes the column of reshape(C, (3,2)) and places it as the row of the new matrix.

permutedims(reshape(C, (3,2)), (2,1))

Output:

2×3 Matrix{Int64}:
 1  2  3
 4  5  6