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

Home » Public Forums » archive » comparing numbers using WHERE doesn't work
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
comparing numbers using WHERE doesn't work [message #25243] Sat, 02 June 2001 12:15 Go to next message
Miklos Z. Kiss is currently offline  Miklos Z. Kiss
Messages: 7
Registered: April 2001
Junior Member
Hi folks:
I have noticed a strange occurence when I try to compare a number with
all the elements of an array. I'll show my situation in an example.
Consider the following array:
a = [2.0000, 2.1000, 2.2000, 2.3000, 2.4000, 2.5000, 2.6000].
Let, x = 2.2000, y = 2.4000
So, I want to find which elements of a match up with x and y.
Naturally, I do the following:


index0 = WHERE(a EQ x)
index0 = index[0] ; convert from 1-D array to single integer.
index1 = WHERE(a EQ y)
index1 = index[0]


So, when I execute, I may get the following:
PRINT, index0
2

PRINT, index1
-1

The output clearly tells me that x occurs at a[2] and that y does not exist
in a at all. By inspection, IDL should return the value 4. Does anyone
have any idea why this happens? Thanks,

Mik Kiss
Re: comparing numbers using WHERE doesn't work [message #25343 is a reply to message #25243] Wed, 06 June 2001 04:47 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
"Miklos Z. Kiss" wrote:
>
> Hi folks:
> I have noticed a strange occurence when I try to compare a number with
> all the elements of an array. I'll show my situation in an example.
> Consider the following array:
> a = [2.0000, 2.1000, 2.2000, 2.3000, 2.4000, 2.5000, 2.6000].
> Let, x = 2.2000, y = 2.4000
> So, I want to find which elements of a match up with x and y.
> Naturally, I do the following:
>
> index0 = WHERE(a EQ x)
> index0 = index[0] ; convert from 1-D array to single integer.
index0 is now redefined by index[0].

> index1 = WHERE(a EQ y)
> index1 = index[0]
index1 is now redefined by index[0].


But where is index redefined normally index0 and
index1 should have the same value.

I believe you missed something in your example.

>
> So, when I execute, I may get the following:
> PRINT, index0
> 2
>
> PRINT, index1
> -1
>

Reimar

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg1/
=============================================
a IDL library at ForschungsZentrum J�lich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml

http://www.fz-juelich.de/zb/text/publikation/juel3786.html
Re: comparing numbers using WHERE doesn't work [message #25363 is a reply to message #25243] Tue, 05 June 2001 06:18 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
"Miklos Z. Kiss" <mzkiss@unity.ncsu.edu> writes:

> Hi folks:
> I have noticed a strange occurence when I try to compare a number with
> all the elements of an array. I'll show my situation in an example.
> Consider the following array:
> a = .
> Let, x = 2.2000, y = 2.4000
> So, I want to find which elements of a match up with x and y.
> Naturally, I do the following:
>
>
> index0 = WHERE(a EQ x)
> index0 = index ; convert from 1-D array to single integer.
> index1 = WHERE(a EQ y)
> index1 = index
>
>
> So, when I execute, I may get the following:
> PRINT, index0
> 2
>
> PRINT, index1
> -1
>
> The output clearly tells me that x occurs at a and that y does not exist
> in a at all. By inspection, IDL should return the value 4. Does anyone
> have any idea why this happens? Thanks,
>
> Mik Kiss

You must have a strange computer system ;-). The above should normally
work, if (1) you are positively sure that all number are single
precision or all numbers are double, (2) you didn't get 2.4000 as a
result of some computation but explicitely wrote it into the vector.

But these 2 conditions show you excatly why you shouldn't use an EQ
comparison on floating point numbers.

Cheers,

Martin


--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
Re: comparing numbers using WHERE doesn't work [message #25373 is a reply to message #25243] Mon, 04 June 2001 14:24 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
"Miklos Z. Kiss" wrote:
>
> Hi folks:
> I have noticed a strange occurence when I try to compare a number with
> all the elements of an array. I'll show my situation in an example.
> Consider the following array:
> a = [2.0000, 2.1000, 2.2000, 2.3000, 2.4000, 2.5000, 2.6000].
> Let, x = 2.2000, y = 2.4000
> So, I want to find which elements of a match up with x and y.
> Naturally, I do the following:
>
> index0 = WHERE(a EQ x)
> index0 = index[0] ; convert from 1-D array to single integer.
> index1 = WHERE(a EQ y)
> index1 = index[0]

What is the vector "index" you reference? I think you must have meant

index0=index0[0]

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: interpolating missing data
Next Topic: Re: IDL 5.4 and MacOS 9.1

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

Current Time: Wed Oct 08 17:40:42 PDT 2025

Total time taken to generate the page: 0.00906 seconds