Re: Replication question [message #45480] |
Thu, 15 September 2005 11:00 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Michael Wallace writes:
> My brain hurts just looking at that. I've tried to read the HISTOGRAM
> tutorial before, and I didn't get very far before my grey matter became
> grey goo. Maybe I'll be able to understand more now that I have a real
> problem I want to solve and will be reading that in a different light.
> It would be easy enough to stick that code in, but I really want to
> understand what's going on. With that in mind, I have written this haiku:
>
> Histogram horror
> How can you understand it?
> Thank you JD Smith
I read it 4-5 times a year, whether I need to or not, and
I *always* learn something new from it. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Replication question [message #45481 is a reply to message #45480] |
Thu, 15 September 2005 10:53  |
Michael Wallace
Messages: 409 Registered: December 2003
|
Senior Member |
|
|
> This is the "chunk indexing problem", which is covered in the
> HISTOGRAM tutorial under "Using the i-Vector". The i-vector is the
> leading portion of the reverse indices vector (the part which,
> narcissistically, indexes itself). See:
>
> http://www.dfanning.com/tips/histogram_tutorial.html
>
> It looks like this:
>
> IDL> h=histogram(total(n,/CUMULATIVE)-1,/BINSIZE,MIN=0,REVERSE_IN DICES=ri)
> IDL> i=ri[0:n_elements(h)-1]-ri[0]
My brain hurts just looking at that. I've tried to read the HISTOGRAM
tutorial before, and I didn't get very far before my grey matter became
grey goo. Maybe I'll be able to understand more now that I have a real
problem I want to solve and will be reading that in a different light.
It would be easy enough to stick that code in, but I really want to
understand what's going on. With that in mind, I have written this haiku:
Histogram horror
How can you understand it?
Thank you JD Smith
-Mike
|
|
|
Re: Replication question [message #45489 is a reply to message #45481] |
Wed, 14 September 2005 16:50  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Wed, 14 Sep 2005 18:09:02 -0500, Michael Wallace wrote:
> Hey guys,
>
> I know there's got to be an easy way to do this, but my brain is cramped
> up right now. Given an array input, I'd like to output an array where the
> index of the of the input array is replicated by the corresponding value
> in the input array. The input array will always contain positive values.
>
> For example...
> input: [1, 2, 1, 4]
> output: [0, 1, 1, 2, 3, 3, 3, 3]
>
> input: [3, 3, 3, 1]
> output: [0, 0, 0, 1, 1, 1, 2, 2, 2, 3]
>
> I know that I could loop over my input array, replicate the loop variable
> by the value of the input array at each position and concatenate the
> resulting arrays, but this solution does not seem like "The IDL Way". Any
> dimensional jugglers out there know a nice looking solution?
This is the "chunk indexing problem", which is covered in the
HISTOGRAM tutorial under "Using the i-Vector". The i-vector is the
leading portion of the reverse indices vector (the part which,
narcissistically, indexes itself). See:
http://www.dfanning.com/tips/histogram_tutorial.html
It looks like this:
IDL> h=histogram(total(n,/CUMULATIVE)-1,/BINSIZE,MIN=0,REVERSE_IN DICES=ri)
IDL> i=ri[0:n_elements(h)-1]-ri[0]
Actually this very example points out a potential problem with the IDL
way: it's not terribly transparent. I suppose if it were, it would
not have a name with such cachet, and a special section devoted to it
on David's site.
JD
|
|
|