# Eachslice(ones(3),dims=2)

**URL:** <https://discourse.julialang.org/t/eachslice-ones-3-dims-2/104907>\
**Category:** General Usage\
**Created:** [October 12, 2023, 6:39pm UTC](https://discourse.julialang.org/t/eachslice-ones-3-dims-2/104907 "2023-10-12T18:39:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [October 12, 2023, 6:39pm UTC](https://discourse.julialang.org/t/eachslice-ones-3-dims-2/104907/1 "2023-10-12T18:39:54Z")

</div>

fails, while `eachslice(ones(3,1),dims=2)` works well. (Similar for other dimensions and higher order dims).  
This is somewhat inconsistent with the fact that `ones(3)[:,1]` does its job, and it is also inconvenient.

EDIT: sorry, I forgot to add that `eachcol(ones(3))` works fine.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [October 12, 2023, 8:30pm UTC](https://discourse.julialang.org/t/eachslice-ones-3-dims-2/104907/2 "2023-10-12T20:30:17Z")

</div>

it seems that eachcol() takes the liberty of treating a vector as a column of a matrix

```julia
julia> @less eachcol(ones(3))
eachcol(A::AbstractVector) = eachcol(reshape(A, size(A, 1), 1))

```

```julia
julia> eachcol(ones(3)).parent
3×1 Matrix{Float64}:
 1.0
 1.0
 1.0

```
