Re: indexing 2-d vs. 3-d arrays...ARGH! [message #43605] |
Wed, 20 April 2005 14:08 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Henry writes:
>> With respect to the web page, I have no current plans
>> to abandon it, although the domain registration comes
>> up for renewal soon and the PayPal contributions have
>> been, well, less than overwhelming. I'd probably have
>> to conclude there are about 5 people who find the
>> information especially useful. :-)
>
> Done.
>
> -Henry
The fine folks at Habitat for Humanity thank you. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: indexing 2-d vs. 3-d arrays...ARGH! [message #43607 is a reply to message #43605] |
Wed, 20 April 2005 13:49  |
Henry
Messages: 8 Registered: April 2005
|
Junior Member |
|
|
> With respect to the web page, I have no current plans
> to abandon it, although the domain registration comes
> up for renewal soon and the PayPal contributions have
> been, well, less than overwhelming. I'd probably have
> to conclude there are about 5 people who find the
> information especially useful. :-)
Done.
-Henry
|
|
|
Re: indexing 2-d vs. 3-d arrays...ARGH! [message #43614 is a reply to message #43607] |
Wed, 20 April 2005 11:15  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Kenneth Bowman writes:
> I'm sure David isn't *really* going away. He only *thinks* he wants
> to go back to college. David is the Michael Jordan of IDL. (Remember
> MJ and baseball?).
You are probably right, but...still, I've pretty much
given up competitive tennis and I *never* thought that
would happen!
I feel like a snake shedding his skin. Who knows
what is possible?
With respect to the web page, I have no current plans
to abandon it, although the domain registration comes
up for renewal soon and the PayPal contributions have
been, well, less than overwhelming. I'd probably have
to conclude there are about 5 people who find the
information especially useful. :-)
Still, I need a forum for all the travel writing I
plan soon. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
Re: indexing 2-d vs. 3-d arrays...ARGH! [message #43616 is a reply to message #43615] |
Wed, 20 April 2005 10:24  |
Henry
Messages: 8 Registered: April 2005
|
Junior Member |
|
|
Yep...it was one of those many things I once knew, but then forgot. I
actually went searching through some old code to see if I'd messed it
up elsewhere. I found I'd taken advantage of this in a couple places
and even left gloating comments about what a neat trick it was!! I
claim graduate school ate my brain.
Let me echo JD's request: David, please, whatever you do, don't let
your web page die. I use it too often, and (more importantly) refer
people to it too often.
cheers,
-Henry
|
|
|
Re: indexing 2-d vs. 3-d arrays...ARGH! [message #43636 is a reply to message #43616] |
Tue, 19 April 2005 16:27  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Tue, 19 Apr 2005 14:39:20 -0700, Henry wrote:
>
> Hey folks,
>
> This one tripped me up today. Wonder how many other places in code
> I've been messed up by it. I (vaguely) understand the logic behind it.
>
> Let's say you want to grab some points out of a 2-d image or a 3-d
> stack of images:
>
> To set the stage, some pretend images and indexes of the points to
> grab:
> arr2 = dindgen(10,10)
> arr3 = dindgen(10,10,5)
> index1 = [2,6]
> index2 = [3,7]
>
> Now,
> help, arr2[index1,index2]
> gives
> <Expression> DOUBLE = Array[2]
> which is what I would expect.
>
> BUT,
> help,arr3[index1, index2, 2]
> gives
> <Expression> DOUBLE = Array[2, 2]
> which is what screwed me up.
>
> IDL demands:
> help,arr3[index1, index2, replicate(2,2)]
> to get:
> <Expression> DOUBLE = Array[2]
>
>
> Get it? Got it? Good.
Why don't you have a read through:
http://dfanning.com/misc_tips/submemory.html
The bottom line? If all indexing arrays match in dimension, as a
special case, IDL "threads the list" and the result has the same size
as each index array. If they don't match, it "inflates the list", by
matching things up one element at a time. So in your middle case, it
sees:
[2,6],[3,7],2
and it says: OK, we're don't have matched index arrays. They must
want 2,6,2; 6,7,2; 6,3,2; 6,7,2. You might argue you really wanted
2,3,2;6,7,2, and would therefore prefer IDL to sub-thread any subset
of the indexing arrays which have matching dimensions. It's not a bad
idea, it just isn't how IDL works.
JD
P.S. David, I hope you don't stop pulling those nuggets from the newgroup
and sticking them on your webpage (or, perish the thought, let your
webpage wither and die).
|
|
|