On Monday, October 5, 2015 at 8:34:35 AM UTC-4, Maxim Berman wrote:
>
> Hello,
>
> I tried to use element-wise equality on list-of-lists in julia:
>
> L = Vector{Int}[[1,2],[2,3]]
> B = (L .== L[1])
>
> However, due to .== broadcasting, this last expression performs an 
> elementwise operation on the two arrays, and therefore returns [false, 
> false]. I don't believe there is a way to circumvent this behavior, since 
> .== is meant to do both array-to-element and array-to-arrays 
> comparison... 
>

You could define a special `.==` method of the form


import Base: .==
.=={T}(A::AbstractArray{T}, b::T) = Bool[a == b for a in A]
.=={T}(b::T, A::AbstractArray{T} = A .== b


to allow .== to work for the case you want without screwing up element-wise 
comparison for other cases.

Reply via email to