# Function like numpy.stack

**URL:** <https://discourse.julialang.org/t/function-like-numpy-stack/39394>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 13, 2020, 11:33am UTC](https://discourse.julialang.org/t/function-like-numpy-stack/39394 "2020-05-13T11:33:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ponez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ponez/32/46571_2.png) [@ponez](https://discourse.julialang.org/u/ponez)\
**Post date:** [May 13, 2020, 11:33am UTC](https://discourse.julialang.org/t/function-like-numpy-stack/39394/1 "2020-05-13T11:33:06Z")

</div>

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
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)

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [May 13, 2020, 12:37pm UTC](https://discourse.julialang.org/t/function-like-numpy-stack/39394/2 "2020-05-13T12:37:01Z")

</div>

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
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

```

---

<div class="post-metadata">

**Author:** ![ponez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ponez/32/46571_2.png) [@ponez](https://discourse.julialang.org/u/ponez)\
**Post date:** [May 13, 2020, 1:40pm UTC](https://discourse.julialang.org/t/function-like-numpy-stack/39394/3 "2020-05-13T13:40:06Z")

</div>

Thinks a lot !
