# Filling arrays in rows

**URL:** <https://discourse.julialang.org/t/filling-arrays-in-rows/25097>\
**Category:** General Usage\
**Created:** [June 9, 2019, 6:15pm UTC](https://discourse.julialang.org/t/filling-arrays-in-rows/25097 "2019-06-09T18:15:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![STHossain](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sthossain/32/8821_2.png) [@STHossain](https://discourse.julialang.org/u/STHossain)\
**Post date:** [June 9, 2019, 6:15pm UTC](https://discourse.julialang.org/t/filling-arrays-in-rows/25097/1 "2019-06-09T18:15:25Z")

</div>

Hi,  
Could someone please help me to figure out how a matrix could be filled in rows. So if I give some numbers with dimension then they would form a 2 dimensional array but it will start filling from the first row, then second and so on. I have seen the reshape command. So for example

> reshape(collect(1:8), 2, 4)  
> 2×4 Array{Int64,2}:  
> 1 3 5 7  
> 2 4 6 8

but I want something like

> 2×4 Array{Int64,2}:  
> 1 2 3 4  
> 5 6 7 8

I know I can create array bu just giving each rows, for example, like this

> 2×4 Array{Int64,2}:  
> 1 2 3 4  
> 5 6 7 8

But is there any a bit more automatic way?

Thanks s a lot for the help

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [June 9, 2019, 6:20pm UTC](https://discourse.julialang.org/t/filling-arrays-in-rows/25097/2 "2019-06-09T18:20:15Z")

</div>

> [@STHossain](#):
>
> reshape(collect(1:8), 2, 4)

Try

```julia
julia> reshape(collect(1:8), 4, 2)'
2×4 Adjoint{Int64,Array{Int64,2}}:
 1 2 3 4
 5 6 7 8

```

I.e., create the transposed array and then transpose it.

---

<div class="post-metadata">

**Author:** ![spaceLem](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/spacelem/32/217628_2.png) [@spaceLem](https://discourse.julialang.org/u/spaceLem)\
**Post date:** [June 9, 2019, 6:24pm UTC](https://discourse.julialang.org/t/filling-arrays-in-rows/25097/3 "2019-06-09T18:24:50Z")

</div>

Or even put the `collect` outside so you end up with just a regular array and not an `Adjoint`.

```julia
julia> collect(reshape(1:8, 4, 2)')
2×4 Array{Int64,2}:
 1 2 3 4
 5 6 7 8

```

---

<div class="post-metadata">

**Author:** ![STHossain](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sthossain/32/8821_2.png) [@STHossain](https://discourse.julialang.org/u/STHossain)\
**Post date:** [June 9, 2019, 6:24pm UTC](https://discourse.julialang.org/t/filling-arrays-in-rows/25097/4 "2019-06-09T18:24:57Z")

</div>

This was so easy, thanks a lot,… so you fill the columns and then transpose, feel like dumb question now.

---

<div class="post-metadata">

**Author:** ![STHossain](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sthossain/32/8821_2.png) [@STHossain](https://discourse.julialang.org/u/STHossain)\
**Post date:** [June 9, 2019, 6:25pm UTC](https://discourse.julialang.org/t/filling-arrays-in-rows/25097/5 "2019-06-09T18:25:33Z")

</div>

Thanks also, now I know two ways
