I have two arrays :
x = [2, 7]
a = [1,2,5,8,4,9]
I would like to know if x is in a so I do that :
x .∈ Ref(a)
This returns :
How can I get the same result but with true and false ([true, false] in this case) instead of 1 and 0 ? So I can use this as a condition :
if x .∈ Ref(a)
When I try it like that i get this error : non-boolean (BitVector) used in boolean context
Thank you !
You already have:
julia> result = in(x)(a)
julia> result = x .∈ Ref(a)
1 you see are just how
false are printed in arrays for compactness.
Why do I have an error : “non-boolean (BitVector) used in boolean context” when I want to use it as a condition in an if statement ?
Probably because you are doing something like this?
julia> if result
ERROR: TypeError: non-boolean (BitVector) used in boolean context
The error is clear if maybe a bit subtle - a
BitVector is not a boolean, it is a vector of booleans, so you can’t use it as a boolean value in an if statement.
Maybe you mean
if all(in(a), x), to check whether all of the elements of
x are in
if any(in(a), x) to check whether any elements of
x are in
Thanks this is what I was looking for !
julia> map(x -> x in a, x)
julia> (x -> x in a).(x)
I think @jnewbie is not aware that
Bool is a
Number type in Julia and many times it is displayed as
1 instead of
true. Their first example already had
Bools I think.