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

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.

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> 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> 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?

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.

1 Like

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

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

Or alternatively, for this specific usage:

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