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

Home » Public Forums » archive » Re: Why does '[1,2,3] EQ [2]' yield zero but '[1,2,3] EQ 2' yield [0,1,0] ?
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: Why does '[1,2,3] EQ [2]' yield zero but '[1,2,3] EQ 2' yield [0,1,0] ? [message #54359] Sat, 02 June 2007 14:13
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
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
Re: Why does '[1,2,3] EQ [2]' yield zero but '[1,2,3] EQ 2' yield [0,1,0] ? [message #54361 is a reply to message #54359] Sat, 02 June 2007 05:44 Go to previous message
wlandsman@jhu.edu is currently offline  wlandsman@jhu.edu
Messages: 12
Registered: September 2006
Junior Member
> 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
Re: Why does '[1,2,3] EQ [2]' yield zero but '[1,2,3] EQ 2' yield [0,1,0] ? [message #54363 is a reply to message #54361] Fri, 01 June 2007 21:29 Go to previous message
sujian is currently offline  sujian
Messages: 10
Registered: May 2007
Junior Member
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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Why does '[1,2,3] EQ [2]' yield zero but '[1,2,3] EQ 2' yield [0,1,0] ?
Next Topic: Re: make_scalar?

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

Current Time: Wed Oct 08 18:40:07 PDT 2025

Total time taken to generate the page: 0.00444 seconds