按行重塑 "filling"

Reshape "filling" by row

有什么简单的方法可以将向量重塑为 "filling" 按行排列的数组吗?

更具体地说,假设我有一个向量

v = collect(1:8)

reshape "fills" 结果数组按列:

reshape(v, (2,2,2))

2x2x2 Array{Int64,3}:
[:, :, 1] =
 1  3
 2  4

[:, :, 2] =
 5  7
 6  8

但我想得到:

a = Array{Int}(2,2,2)
a[:, :, 1] = [1 2; 3 4]
a[:, :, 2] = [5 6; 7 8]

a
2x2x2 Array{Int64,3}:
[:, :, 1] =
 1  2
 3  4

[:, :, 2] =
 5  6
 7  8

这将是添加到 reshape 的一个不错的选择。

mapslices(transpose,reshape(v, (2,2,2)),[1,2])

您缺少的关键字是 "transpose"。剩下的我刚从 the docs