# How can i separate between two arrays inside a parent array?

**URL:** <https://discourse.julialang.org/t/how-can-i-separate-between-two-arrays-inside-a-parent-array/45744>\
**Category:** General Usage\
**Created:** [August 29, 2020, 2:05pm UTC](https://discourse.julialang.org/t/how-can-i-separate-between-two-arrays-inside-a-parent-array/45744 "2020-08-29T14:05:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [August 29, 2020, 2:05pm UTC](https://discourse.julialang.org/t/how-can-i-separate-between-two-arrays-inside-a-parent-array/45744/1 "2020-08-29T14:05:15Z")

</div>

this code is a small example of what i want to do, i have this small example right here:

```julia
y=[[[1,0],[0,0],[1,1],[1,0],[1,0],[0,1]],[[1,0],[0,0],[1,1],[0,0]],[[1,0],[0,0],[1,1],[1,0],[1,0],[1,0]]]
array=[]
all_array=[]
for i in 1:length(y)
    for j in 1: length(y[i])
        if y[i][j]==[1,0]
            push!(array,y[i][j])
        end
        
    end
end

```

what i’m expecting when you return `array` is this :

```julia
[[[1,0],[1,0],[1,0]],[[1,0]],[[1,0],[1,0],[1,0],[1,0]]]

```

which is `3-element Array{Array{Array{Int64,1},1},1}` but instead i get this:

```julia
8-element Array{Any,1}:
 [1, 0]
 [1, 0]
 [1, 0]
 [1, 0]
 [1, 0]
 [1, 0]
 [1, 0]
 [1, 0]

```

i don’t know what i’m missing here.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 29, 2020, 2:32pm UTC](https://discourse.julialang.org/t/how-can-i-separate-between-two-arrays-inside-a-parent-array/45744/2 "2020-08-29T14:32:16Z")

</div>

```julia
filter.(==([1,0]), y)

```

Should do what you want.

* * *

Edit  
The reason your array is coming out “flat” is that you’re `push`ing all of the `[1, 0]` matches to the same array. If you wanted to write a function to do it yourself, think about writing it for each `y[i]` individually, and then calling that inner function in a loop over the arrays in `y`.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [August 30, 2020, 3:09am UTC](https://discourse.julialang.org/t/how-can-i-separate-between-two-arrays-inside-a-parent-array/45744/3 "2020-08-30T03:09:31Z")

</div>

Or some array comprehension,

```julia
julia> [[x for x in yi if x==[1,0]] for yi in y]
3-element Array{Array{Array{Int64,1},1},1}:
 [[1, 0], [1, 0], [1, 0]]
 [[1, 0]]
 [[1, 0], [1, 0], [1, 0], [1, 0]]

```

which is the translation of the nested loops:

```julia
array = similar(y,0);
for i in y
    arri = similar(i,0)
    for j in i
        j == [1,0] && push!(arri,j)
    end
    push!(array,arri)
end

```

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [August 30, 2020, 8:57am UTC](https://discourse.julialang.org/t/how-can-i-separate-between-two-arrays-inside-a-parent-array/45744/4 "2020-08-30T08:57:12Z")

</div>

the first method is brilliant and it’s working

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [August 30, 2020, 8:57am UTC](https://discourse.julialang.org/t/how-can-i-separate-between-two-arrays-inside-a-parent-array/45744/5 "2020-08-30T08:57:33Z")

</div>

indeed
