Suppose I have the following array:
a=[NaN, 1,2,3]
If I use findmax(a), I obtain (NaN, 1). How can I use findmax() ignoring all NaN values? I tried findmax(filter(!isnan, a)) but it returns (3.0,3) when I want (3.0,4).
Thank you!
Suppose I have the following array:
a=[NaN, 1,2,3]
If I use findmax(a), I obtain (NaN, 1). How can I use findmax() ignoring all NaN values? I tried findmax(filter(!isnan, a)) but it returns (3.0,3) when I want (3.0,4).
Thank you!
One bandaid fix is to first set them to -Inf (or Inf if you are doing findmin).
a[ isnan.(a)] .= -Inf
Thanks! Worked perfectly!!
I expected
findmax(Iterators.filter(!isnan, a))
to work but it appers to be broken because of
I would do:
julia> findmax(a[.!isnan.(a)])
(3.0, 3)
Ahhhh gooood! Another good option! Thanks! But I want (3.0, 4) and not (3.0,3) as I specified ![]()
Ah ok… Right, it doesn’t work ![]()
MappedArrays.jl is good for this too:
julia> m = mappedarray(x -> isfinite(x) ? x : -Inf, a);
julia> findmax(m)
(3.0, 4)
Ok! Didn’t know about this package! ![]()