How to check if two arrays are equal even if they contain NaN values in Julia?
Use isequal
:
Similar to
==
, except for the treatment of floating point numbers and of missing values.isequal
treats all floating-pointNaN
values as equal to each other, treats-0.0
as unequal to0.0
, andmissing
as equal tomissing
. Always returns aBool
value.
julia> a = [1,2, NaN]
3-element Array{Float64,1}:
1.0
2.0
NaN
julia> b = [1,2, NaN]
3-element Array{Float64,1}:
1.0
2.0
NaN
julia> isequal(a, b)
true
You probably want to use isequal(a, b)
(which also treats missing
equal to missing
, but -0.0
as unequal to 0.0
).