Vector/array and boolean mask using logic operators

Hi,

I would like to do the same thing as in Python:

import numpy as np

arr=np.array([1,2,3,4,5,6])
mask=(arr<3)|(arr>=4)

which gives as result

array([ True,  True, False,  True,  True,  True])

I tried stuff in Julia, but mostly went into:

ERROR: TypeError: non-boolean (BitVector) used in boolean context

Not sure what you tried in Julia, but this works:

julia> arr = collect(1:6);

julia> mask = (arr .< 3) .|| (arr .>= 4)
6-element BitVector:
 1
 1
 0
 1
 1
 1

Or

julia> .!in(3:4).(arr)

Thanks a lot !

I was trying stuff like:

mask = isless.() || isequal.() || isless.()

The key is to use a dot that tells Julia the operation is applied elementwise (which numpy does by default):

julia> x = [true, false]
2-element Vector{Bool}:
 1
 0

julia> x || x
ERROR: TypeError: non-boolean (Vector{Bool}) used in boolean context
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

julia> x .|| x
2-element BitVector:
 1
 0