A julia function to stack two arrays of size (m, n), to get one of size (2, m, n)

cat and permutedims should do the trick

julia> a = rand(1:10, 4, 3)
4×3 Array{Int64,2}:
 10   6  5
  9  10  9
  7   8  2
  1   4  2

julia> b = rand(11:20, 4, 3)
4×3 Array{Int64,2}:
 11  19  11
 17  16  19
 13  18  13
 20  16  16

julia> cat(a,b; dims=3)
4×3×2 Array{Int64,3}:
[:, :, 1] =
 10   6  5
  9  10  9
  7   8  2
  1   4  2

[:, :, 2] =
 11  19  11
 17  16  19
 13  18  13
 20  16  16

julia> permutedims(ans, [3, 1, 2])
2×4×3 Array{Int64,3}:
[:, :, 1] =
 10   9   7   1
 11  17  13  20

[:, :, 2] =
  6  10   8   4
 19  16  18  16

[:, :, 3] =
  5   9   2   2
 11  19  13  16
4 Likes