Re: array handling [message #52113] |
Mon, 08 January 2007 09:43  |
news.qwest.net
Messages: 137 Registered: September 2005
|
Senior Member |
|
|
"Brian Larsen" <balarsen@gmail.com> wrote in message
news:1168100109.828745.131590@11g2000cwr.googlegroups.com...
> Something I have always wondered is the difference between using
> finite() and just using ne?
>
> As an example:
> IDL> array = [ 1.0, 2.0, !Values.F_NAN, 4.0, !Values.F_NAN ]
> IDL> Print, Where( NOT Float( Finite(array) ) )
> 2 4
> IDL> print, where(array ne array)
> 2 4
>
> What is the fundamental difference here? Speed? Style? or something
> else entirely?
>
> Cheers,
>
> Brian
while where(array ne array) is clever, short, and possibly fast
one should note (from IDL help):
"On Windows, using relational operators such as EQ and NE
with the values infinity or NaN (Not a Number) causes an "illegal operand"
error"
Programmers will generally avoid depending on a result that flags an error,
and is not strictly defined in the language. The results may change in
different versions
of IDL, and perahps on different operating systems. Who knows, in version 7,
IDL may
decide to make nan eq nan return 1.
Cheers,
bob
|
|
|
|
Re: array handling [message #52122 is a reply to message #52121] |
Sat, 06 January 2007 08:47   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Brian Larsen writes:
> Something I have always wondered is the difference between using
> finite() and just using ne?
>
> As an example:
> IDL> array = [ 1.0, 2.0, !Values.F_NAN, 4.0, !Values.F_NAN ]
> IDL> Print, Where( NOT Float( Finite(array) ) )
> 2 4
> IDL> print, where(array ne array)
> 2 4
>
> What is the fundamental difference here? Speed? Style? or something
> else entirely?
I don't know the answer, but I would guess the latter formulation
would lead some programmers to a general feeling of unease
regarding treating things that aren't numbers as if they were.
There are no hard and fast rules for such things, I don't think,
so you are at the mercy of programmers you don't know and
implementations that could, I guess, change in the future.
Plus, you get that damn "Arithmetic error: Floating illegal operation"
message when you try it. That generally causes a loss of confidence
among customers. :-(
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
Re: array handling [message #52124 is a reply to message #52123] |
Sat, 06 January 2007 08:15   |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
Something I have always wondered is the difference between using
finite() and just using ne?
As an example:
IDL> array = [ 1.0, 2.0, !Values.F_NAN, 4.0, !Values.F_NAN ]
IDL> Print, Where( NOT Float( Finite(array) ) )
2 4
IDL> print, where(array ne array)
2 4
What is the fundamental difference here? Speed? Style? or something
else entirely?
Cheers,
Brian
On Jan 6, 8:01 am, David Fanning <n...@dfanning.com> wrote:
> jochem.vere...@gmail.com writes:
>> I am a newbie in IDL. Although I cannot handle the following problem, I
>> am sure for the 'Masters' this is peanuts.
>
>> The problem:
>> I wish to filter an array of redundant data in one line. This is a part
>> of the line to be filtered:
>
>> -Inf -NaN -Inf 0.542373 2.39394 2.28125
>> 0.000000 0.000000 0.000000
>> 3.21053 1.21839 0.000000 -NaN 0.967213
>> 2.03448 0.724138 0.000000 0.000000 0.000000
>> -NaN
>
>> With WHERE I can get rid of the zeros, but I dont know how to exclude
>> the '-NaN' and '-Inf'.
>
>> Any help would be most welcome,Here is an article that will help:
>
> http://www.dfanning.com/tips/check_nan.html
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
Re: array handling [message #52218 is a reply to message #52113] |
Thu, 11 January 2007 07:27  |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
>> Brian while where(array ne array) is clever, short, and possibly fast
> one should note (from IDL help):
> "On Windows, using relational operators such as EQ and NE
> with the values infinity or NaN (Not a Number) causes an "illegal operand"
> error"
This would explain why I had never seen the error that David mentioned
before. In Linux it just goes on its merry way w/o errors. But in the
future I think I will move to finite.
Brian
|
|
|