comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: How to locate a "NaN"?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: How to locate a "NaN"? [message #56257] Tue, 09 October 2007 05:22
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
No Message Body
Re: How to locate a "NaN"? [message #56265 is a reply to message #56257] Tue, 09 October 2007 01:26 Go to previous message
lasse is currently offline  lasse
Messages: 48
Registered: February 2007
Member
On 9 Oct, 07:12, mystea <idllear...@gmail.com> wrote:
> Hello All,
>
> I have a array of length 100. A significant portion of them is
> recorded as NaN. Now I want to figure out what is the largest index of
> the element that contains a valid number, then assign its value to
> these NaN entries.
>
> I thought it would be easy and tried:
>
> IDL> k=max(where(myarray[*] ne !VALUES.D_NAN))
>
> but it does not work! k equals to 99 in this case. what's really
> strange is the following:
>
> IDL> help, myarray[50]
> <Expression> DOUBLE = NaN
>
> IDL>print, (myarray[50] eq !VALUES.D_NAN)
> 0
> (so I think this means myarray[50] is double, is NAN, yet is not !
> VALUES.D_NAN)
>
> In short, the problem is, how to locate array elements whose values
> are NaN?

It might be worth noting here that *nothing* is equal to NaNs. Even

!values.f_nan eq !values.f_nan and
!values.d_nan eq !values.d_nan

returns false (at least on my machine, there might be differences
between different platforms, although there shouldn't). This result is
obvious, really, because if it is a NaN (=Not A Number), how can it be
equal to anything?

And fanxing is right, only the finite() function will tell you where
NaNs are.

Cheers
Lasse
Re: How to locate a "NaN"? [message #56266 is a reply to message #56265] Tue, 09 October 2007 00:36 Go to previous message
fanxing_gis is currently offline  fanxing_gis
Messages: 8
Registered: August 2007
Junior Member
On 10 9 , 2 12 , mystea <idllear...@gmail.com> wrote:
> Hello All,
>
> I have a array of length 100. A significant portion of them is
> recorded as NaN. Now I want to figure out what is the largest index of
> the element that contains a valid number, then assign its value to
> these NaN entries.
>
> I thought it would be easy and tried:
>
> IDL> k=max(where(myarray[*] ne !VALUES.D_NAN))
>
> but it does not work! k equals to 99 in this case. what's really
> strange is the following:
>
> IDL> help, myarray[50]
> <Expression> DOUBLE = NaN
>
> IDL>print, (myarray[50] eq !VALUES.D_NAN)
> 0
> (so I think this means myarray[50] is double, is NAN, yet is not !
> VALUES.D_NAN)
>
> In short, the problem is, how to locate array elements whose values
> are NaN?

you could use finite() to do it, and try this:
IDL> k=max(where(finite(myarray) eq 0))
k is the largest index of elements whose values are valid.
By the way, !VALUES.D_NAN in not equal to !VALUES.F_NAN,your data type
is long or float?

best wishes

fanxing
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Get unlimited visitors to your website
Next Topic: y axis tickmarks and box_plot

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:40:41 PDT 2025

Total time taken to generate the page: 0.00444 seconds