在Array上使用fill(),同时在Julia中维护一般结构

Ale*_*aun 3 arrays julia

例如,如果我们有

a=[1 2;3 4]
Run Code Online (Sandbox Code Playgroud)

我们想要重复每个元素(在一个单独的列中)2次,结果是:

[1 1 2 2;3 3 4 4]
Run Code Online (Sandbox Code Playgroud)

我试过了

hcat([fill(a[n],2) for n=1:length(a)]...)
Run Code Online (Sandbox Code Playgroud)

但那又归来了

[1 3 2 4;1 3 2 4]
Run Code Online (Sandbox Code Playgroud)

有关如何实现我想要的结果的任何想法?

谢谢您的帮助!

Mat*_* B. 5

使用repeat功能:

julia> repeat(a, inner=(1, 2))
2×4 Array{Int64,2}:
 1  1  2  2
 3  3  4  4
Run Code Online (Sandbox Code Playgroud)

inner关键字指定要重复的元素(而不是整个阵列本身),并(1,2)指定该行不会重复,但列复制.