Function like numpy.stack

Is there any function like numpy.stack(arrays, axis=),I’ve tried repeat(a, inner=()), but this method can’t specify axis, and reshape after repeat doesn’t work.

julia> a
2-element Array{Int64,1}:
 2
 1
julia> c = repeat(a, inner=(1,1,3))
2×1×3 Array{Int64,3}:
[:, :, 1] =
 2
 1

[:, :, 2] =
 2
 1

[:, :, 3] =
 2
 1

julia> c[:,:,2] == reshape(c, 3, 2, 1)[2,:,:]
false

I want to stack 3 array a to (3, 2, 1) and c[1,:,:] == a (and 2:3)

Here are a few ways to do what you might be asking. Since Julia’s arrays are column-major, it is more common to think of slices as occupying the first dimensions than the last.

julia> as = [rand(Int8, 2) for _ in 1:3]
3-element Array{Array{Int8,1},1}:
 [-113, 90]
 [-42, 13]
 [-25, -74]

julia> reduce(hcat, as)
2×3 Array{Int8,2}:
 -113  -42  -25
   90   13  -74

julia> [a[i] for i in eachindex(first(as)), a in as]
2×3 Array{Int8,2}:
 -113  -42  -25
   90   13  -74

julia> LazyStack.stack(as)
2×3 stack(::Array{Array{Int8,1},1}) with eltype Int8:
 -113  -42  -25
   90   13  -74

julia> JuliennedArrays.Align(as, 1)
2×3 Align{Int8,2,Array{Array{Int8,1},1},Tuple{True,False}}:
 -113  -42  -25
   90   13  -74
3 Likes

Thinks a lot !