|
Re: How to locate a "NaN"? [message #56265 is a reply to message #56257] |
Tue, 09 October 2007 01:26  |
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  |
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
|
|
|