polistes
polistes

Reputation: 31

Julia dot operator and boolean

Suppose I have p = [true, true, false, false] and q = [true, false, true, false]. How can I logically "and" them, say like p .&& q?

Upvotes: 3

Views: 295

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69949

Use .& instead:

julia> p=[true, true, false, false]
4-element Array{Bool,1}:
 1
 1
 0
 0

julia> q=[true, false, true, false]
4-element Array{Bool,1}:
 1
 0
 1
 0

julia> p .& q
4-element BitArray{1}:
 1
 0
 0
 0

You have to be careful though as & works also on non-Bool elements:

julia> [11,12,13] .& [3,2,1]
3-element Array{Int64,1}:
 3
 0
 1

Upvotes: 3

Related Questions