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

Home » Public Forums » archive » Re: MEDIAN and double?
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: MEDIAN and double? [message #30772] Fri, 17 May 2002 19:49
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Pavel A. Romashkin" <pavel_romashkin@hotmail.com> writes:

> I always thought that MEDIAN in Double is just
>
> print, (the_data[sort(the_data)])[n_elements(the_data)/2]

That works for a single number, but the nice part about MEDIAN is that
it can be applied with a sliding window, as in,

ysmooth = median(y, window)

But, if your data have double precision then YSMOOTH is not always
high enough precision to respect the original data. Or, at least,
mine didn't.

For example, consider:

IDL> print, median(1d + 2.4d-9 + [0,0]) - 1
0.00000

Whoops!

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: MEDIAN and double? [message #30775 is a reply to message #30772] Fri, 17 May 2002 15:18 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
That's very strange. It appears that MEDIAN always returns a floating point
value, even if the input array is integer. I suspect this is because of the
/EVEN keyword, where it interpolates between two values if the number of points
is even. It should be smarter than that.

William Thompson


"Pavel A. Romashkin" <pavel_romashkin@hotmail.com> writes:

> I always thought that MEDIAN in Double is just

> print, (the_data[sort(the_data)])[n_elements(the_data)/2]

> but I may be wrong.
> Cheers,
> Pavel

> Craig Markwardt wrote:
>>
>> Is it true that MEDIAN only works in single precision? I've tried to
>> use a /DOUBLE keyword and it doesn't have one. This is kind of a
>> stumper since I certainly do use MEDIAN on double precision
>> data... :-)
>>
>> Craig
>>
>> --
>> ------------------------------------------------------------ --------------
>> Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
>> Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
>> ------------------------------------------------------------ --------------
Re: MEDIAN and double? [message #30778 is a reply to message #30775] Fri, 17 May 2002 14:38 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
I always thought that MEDIAN in Double is just

print, (the_data[sort(the_data)])[n_elements(the_data)/2]

but I may be wrong.
Cheers,
Pavel

Craig Markwardt wrote:
>
> Is it true that MEDIAN only works in single precision? I've tried to
> use a /DOUBLE keyword and it doesn't have one. This is kind of a
> stumper since I certainly do use MEDIAN on double precision
> data... :-)
>
> Craig
>
> --
> ------------------------------------------------------------ --------------
> Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
> Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
> ------------------------------------------------------------ --------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: sample mean and parametric mean?
Next Topic: Seg. Fault in IDL 5.5 (Linux)

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

Current Time: Wed Oct 08 15:39:15 PDT 2025

Total time taken to generate the page: 0.00681 seconds