# Findall() not behaving well for an array of size 1

**URL:** <https://discourse.julialang.org/t/findall-not-behaving-well-for-an-array-of-size-1/127839>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 8, 2025, 11:25am UTC](https://discourse.julialang.org/t/findall-not-behaving-well-for-an-array-of-size-1/127839 "2025-04-08T11:25:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atiyabzafar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atiyabzafar/32/50322_2.png) [@atiyabzafar](https://discourse.julialang.org/u/atiyabzafar)\
**Post date:** [April 8, 2025, 11:25am UTC](https://discourse.julialang.org/t/findall-not-behaving-well-for-an-array-of-size-1/127839/1 "2025-04-08T11:25:34Z")

</div>

Hi, I was just implementing a code for my work and inside a very long code, I had used findall() to find the set of numbers that satisfy certain property. But I found an unexpected result and when I tried debugging the code found this behaviour. Which feels to be wrong.

```Julia
nums=[1,2,3]
test=[1,2,3,4,5,6]
choicenonnums=findall(x->x∉nums,test)

```

This provides the right output, which is all the numbers in the array `test` that are not in `nums` array.

```julia
julia> choicenonnums=findall(x->x∉nums,test)
3-element Vector{Int64}:
 4
 5
 6

```

But when I change the test array as a single number array. Or an array of length 1. It gives [1] as output.

```julia
julia> test=[75]
1-element Vector{Int64}:
 75

julia> choicenonnums=findall(x->x∉nums,test)
1-element Vector{Int64}:
 1

```

Is this some obscure use of findall() that I am not aware of? Or is this a bug?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 8, 2025, 11:28am UTC](https://discourse.julialang.org/t/findall-not-behaving-well-for-an-array-of-size-1/127839/2 "2025-04-08T11:28:51Z")

</div>

`findall` returns the indices of the elements satisfying the condition (not the elements themselves). And element 1 of `test` is the number `75`, which is not in `[1,2,3]`, thus that’s what’s expected.

---

<div class="post-metadata">

**Author:** ![atiyabzafar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atiyabzafar/32/50322_2.png) [@atiyabzafar](https://discourse.julialang.org/u/atiyabzafar)\
**Post date:** [April 8, 2025, 11:31am UTC](https://discourse.julialang.org/t/findall-not-behaving-well-for-an-array-of-size-1/127839/3 "2025-04-08T11:31:56Z")

</div>

Thanks I forgot that line of the code. That is the solution

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 8, 2025, 11:35am UTC](https://discourse.julialang.org/t/findall-not-behaving-well-for-an-array-of-size-1/127839/4 "2025-04-08T11:35:59Z")

</div>

Additionally, if it is the values you want to have you can just replace `findall` with `filter` in these examples.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 8, 2025, 11:59am UTC](https://discourse.julialang.org/t/findall-not-behaving-well-for-an-array-of-size-1/127839/5 "2025-04-08T11:59:11Z")

</div>

> [@atiyabzafar](#):
>
> ```julia
> nums=[1,2,3]
> test=[1,2,3,4,5,6]
> 
> ```

Or alternatively, for this specific usage:

```julia
julia> setdiff(test, nums)
3-element Vector{Int64}:
 4
 5
 6

```
