how to test NaN in an array?

3,993 views
Skip to first unread message

Evan Pu

unread,
Dec 15, 2014, 3:33:55 PM12/15/14
to julia...@googlegroups.com
1 in [1,2,3] # returns true

NaN in [NaN, 1.0, 2.0] # returns false

how do I test if a float64 NaN is present in an array? I'm doing some numerical computation and it can have some NaN error, I want to drop the arrays that has NaN.

John Myles White

unread,
Dec 15, 2014, 3:35:22 PM12/15/14
to julia...@googlegroups.com
You need to check isnan() per element. NaN == NaN is false, so in() fails on NaN right now.

-- John

Miles Lubin

unread,
Dec 15, 2014, 3:54:09 PM12/15/14
to julia...@googlegroups.com
any(isnan,arr) is probably the most compact syntax.

Evan Pu

unread,
Dec 15, 2014, 5:58:38 PM12/15/14
to julia...@googlegroups.com
come to think of it that is the right semantics.
well designed language this is!

Stefan Karpinski

unread,
Dec 15, 2014, 6:36:19 PM12/15/14
to Julia Users
It's arguable that `in` should use `isequal` for comparison since that's what a Dict does.

Toivo Henningsson

unread,
Dec 16, 2014, 6:40:02 AM12/16/14
to julia...@googlegroups.com
+1

Stefan Karpinski

unread,
Dec 16, 2014, 11:49:46 AM12/16/14
to Julia Users

On Tue, Dec 16, 2014 at 6:40 AM, Toivo Henningsson <toiv...@gmail.com> wrote:
+1

Reply all
Reply to author
Forward
0 new messages