f



Why does '[1,2,3] EQ [2]' yield zero but '[1,2,3] EQ 2' yield [0,1,0] ?

Hi all,

The post title says it all. I thought "everything" in IDL was an
array, but using [2] and 2 with relational operators is not
equivalent...

I searched the doc and newsgroup for quite a while, but obviously I
did not come up with search terms that are specific enough.

It took me a while to track this down in some code I was writing. My
bug is now fixed *but* I don't understand why exactly. And we all know
voodoo and IDL don't mix :-) can somebody clarify please?


Many thanks,
Gianguido

PS: I have a feeling this issue came up not too long ago, just
couldn't find it. Sorry :-( Feel free to dispense with this question
with a link.

0
6/2/2007 2:18:22 AM
comp.lang.idl-pvwave 12260 articles. 4 followers. Post Follow

3 Replies
1118 Views

Similar Articles

[PageSpeed] 20

On Jun 1, 10:18 pm, Gianguido Cianci <gianguido.cia...@gmail.com>
wrote:
> Hi all,
>
> The post title says it all. I thought "everything" in IDL was an
> array, but using [2] and 2 with relational operators is not
> equivalent...
>
> I searched the doc and newsgroup for quite a while, but obviously I
> did not come up with search terms that are specific enough.
>
> It took me a while to track this down in some code I was writing. My
> bug is now fixed *but* I don't understand why exactly. And we all know
> voodoo and IDL don't mix :-) can somebody clarify please?
>
> Many thanks,
> Gianguido
>
> PS: I have a feeling this issue came up not too long ago, just
> couldn't find it. Sorry :-( Feel free to dispense with this question
> with a link.


my guess:

[1,2,3] EQ [2] compares two sets, one with 3 elements and the other 1.


[1,2,3] EQ 2 compares each element of the first set with number 2.


0
sujian (10)
6/2/2007 4:29:28 AM

> my guess:
>
> [1,2,3] EQ [2] compares two sets, one with 3 elements and the other 1.
>
I think the better rule to remember is that when comparing two vectors, IDL 
will truncate the longer vector prior to the comparison so that the two 
vectors have the same length.   So [1,2,3] EQ [2] is the same as [1] EQ [2]. 
For another example,

IDL> print, [1,2,3] eq [1,2]
 1   1

>
> [1,2,3] EQ 2 compares each element of the first set with number 2.
>
That is correct.  --Wayne 


0
wlandsman1 (24)
6/2/2007 12:44:49 PM
On Jun 2, 12:29 am, suj...@gmail.com wrote:
> my guess:
>
> [1,2,3] EQ [2] compares two sets, one with 3 elements and the other 1.
>
> [1,2,3] EQ 2 compares each element of the first set with number 2.

I think Wayne (below) is correct, actually, since if you compare
[1,2,3] with 1 or [1] you get:

IDL> print, [1,2,3] eq 1
   1   0   0
IDL> print, [1,2,3] eq [1]
   1

It seems that [1,2,3] is truncated to one element.


Thanks to both of you for your help,
Gianguido

0
6/2/2007 9:13:16 PM
Reply: