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

Home » Public Forums » archive » Re: Replication question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Replication question [message #45489 is a reply to message #45481] Wed, 14 September 2005 16:50 Go to previous message
JD Smith is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: contour outside the limits
Next Topic: Writing JPEG2000 file

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

Current Time: Sun Nov 30 15:13:44 PST 2025

Total time taken to generate the page: 1.19659 seconds