reshape向量成矩阵怎样简单的转成按行排数据?

julia> x = Vector(0:11)
12-element Vector{Int64}:
0
1
2
3
4
5
6
7
8
9
10
11

julia> reshape(x, 3, :slight_smile:
3×4 Matrix{Int64}:
0 3 6 9
1 4 7 10
2 5 8 11

numpy中:
X = x.reshape(3, 4)
array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.]])

Julia中是列索引优先的

:sweat_smile: 简单的方法, 把行和列数交换再转置下

julia> reshape(x, 4, :)'
3×4 adjoint(::Matrix{Int64}) with eltype Int64:
 0  1   2   3
 4  5   6   7
 8  9  10  11

行优先和列优先一般都是根据语言进行选择的,只要保证最终的结果一致即可,不必强求中间显示结果也相同。