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

Home » Public Forums » archive » Re: Mean and NaNs
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: Mean and NaNs [message #83117] Wed, 06 February 2013 11:06
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
Hi Craig,

On 02/06/2013 06:38 PM, Craig Markwardt wrote:
> What do you expect to happen when*all* of the values are NAN?

I expect a NaN.

So the result of mean() is consistent to me, but the "Floating illegal
operand" is annoying.

For example, I have a 3D array of geopotential heights at a certain
pressure level, some of the pixels are always NaNs because of
topography. I compute means on the third dimension which is time. When I
Plot the results, I can go along automatically with NaNs in my data
image. I just find it awkward and inefficient to have to write a case
for these pixels, just to remove the "Floating illegal operand" warning...

But it seems quite useless to argue in this direction, my precious posts
on the inconsistency in value_locate() results with NaNs also found not
much interest

Anyway, thanks for your answer!

Fab
Re: Mean and NaNs [message #83123 is a reply to message #83117] Wed, 06 February 2013 09:38 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Wednesday, February 6, 2013 8:16:35 AM UTC-8, Fab wrote:
> Hi IDLers,
>
>
>
> I know I have been annoying with NaNs lately, but is the following
> "Floating illegal operand" supposed to happen???
>
>
>
> IDL> print, !VERSION
> { x86_64 linux unix linux 8.2.2 Jan 23 2013 64 64}
> IDL> data = FINDGEN(10,10,10)
> IDL> data[5,5,*] = !VALUES.F_NAN
>
> IDL> help, mean(data, /NAN)
> <Expression> FLOAT = 499.444
> IDL> help, mean(data, DIMENSION=3, /NAN)
> <Expression> FLOAT = Array[10, 10]
> % Program caused arithmetic error: Floating illegal operand
>
> Which is related to:
> IDL> print, mean(!VALUES.F_NAN)
> NaN
> IDL> print, mean(!VALUES.F_NAN, /NAN)
> -NaN
> % Program caused arithmetic error: Floating illegal operand
>
> Is it my job to catch those cases or is something wrong?

The behavior of MEAN(x,/NAN) is to exclude NAN values from the mean calculation.

What do you expect to happen when *all* of the values are NAN?

Actually this is kind of a failure of the IDL documentation to say what happens in these cases.

CM
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: controling a warped image: How to do it?
Next Topic: Re: Can't find the end of a text file

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

Current Time: Wed Oct 08 13:47:21 PDT 2025

Total time taken to generate the page: 0.00601 seconds