# How do I turn this into arrays?

**URL:** <https://discourse.julialang.org/t/how-do-i-turn-this-into-arrays/30784>\
**Category:** General Usage\
**Created:** [November 6, 2019, 9:33am UTC](https://discourse.julialang.org/t/how-do-i-turn-this-into-arrays/30784 "2019-11-06T09:33:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexanderChen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexanderchen/32/22007_2.png) [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Post date:** [November 6, 2019, 9:33am UTC](https://discourse.julialang.org/t/how-do-i-turn-this-into-arrays/30784/1 "2019-11-06T09:33:25Z")

</div>

Hi,

This code works but the output is 1 single array:

```julia
[10 - i - j for i in collect(0:9), j in collect(0:9) if 10- i - j > 0]

```

output:

```julia
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 4, 3, 2, 1, 3, 2, 1, 2, 1, 1]

```

How do I change it to be:

```julia
[[10,9,8,7,6,5,4,3,2,1],[9,8,7,6,5,4,3,2,1],[8,7,6,5,4,3,2,1],[7,6,5,4,3,2,1],[6,5,4,3,2,1],[5,4,3,2,1],[4,3,2,1],[3,2,1],[2,1],[1]]

```

What am i not doing correct?

best,

---

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [November 6, 2019, 9:36am UTC](https://discourse.julialang.org/t/how-do-i-turn-this-into-arrays/30784/2 "2019-11-06T09:36:34Z")

</div>

Like so?

```julia
julia> [[10 - i - j for i in 0:9 if 10- i - j > 0] for j in 0:9]
10-element Array{Array{Int64,1},1}:
 [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
 [9, 8, 7, 6, 5, 4, 3, 2, 1]    
 [8, 7, 6, 5, 4, 3, 2, 1]       

```

Also note that writing `for i in collect(0:9)` is never necessary. Just about the only reason to `collect` a range is if you wish to mutate the resulting Array.

---

<div class="post-metadata">

**Author:** ![AlexanderChen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexanderchen/32/22007_2.png) [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Post date:** [November 6, 2019, 9:43am UTC](https://discourse.julialang.org/t/how-do-i-turn-this-into-arrays/30784/3 "2019-11-06T09:43:51Z")

</div>

@improbable22: you read my mind. When i saw your code I started to wonder if collect() was redundant!  
So I am suppose to put the second for-loop outside to achieve this. Cool thanks!
