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

Home » Public Forums » archive » Re: help with chunk indexing
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: help with chunk indexing [message #54641] Mon, 02 July 2007 05:42 Go to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
Here's a simpler way...

IDL> inds = [0,1,1,2,3,3 ,3 ,3]
IDL> n = [1,2,1,4]
IDL> c=[0,total(n,/cum,/int)]
IDL> print,indgen(n_elements(inds))-c[inds]
0 0
1 0 0
1 2 3

For the life of me, I can't remember how to transform n = [1,2,1,4]
==> inds = [0,1,1,2,3,3 ,3 ,3] - I spent ages reading the IDL function
list, but I can't find it...

many greetings,
Greg
Re: help with chunk indexing [message #54644 is a reply to message #54641] Mon, 02 July 2007 02:53 Go to previous messageGo to next message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Fri, 29 Jun 2007 19:51:14 -0000, "Matt B." <becker.mr@gmail.com>
wrote:

> But what is a fast way to do this
> n = [1,2,1,4] ==> inds = [0,0,1,0,0,1 ,2 ,3]

Maybe there is a more clever way, but this works:

in=[1,2,1,4]
h=histogram(total(in,/CUMULATIVE,/PRESERVE_TYPE)-1,/BINSIZE, MIN=0,REVERSE_INDICES=ri)
nh=n_elements(h)

i=ri[0:nh-1]-ri[0]
ind=shift(i,-1)-i
ind=[1,ind[0:nh-2]]
out=indgen(nh)-(where(ind))[i]

print,out ;[0,0,1,0,0,1 ,2 ,3]
Re: help with chunk indexing [message #54780 is a reply to message #54641] Tue, 03 July 2007 01:11 Go to previous message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Mon, 02 Jul 2007 05:42:08 -0700, greg.addr@googlemail.com wrote:

>
> Here's a simpler way...
>
> IDL> inds = [0,1,1,2,3,3 ,3 ,3]
> IDL> n = [1,2,1,4]
> IDL> c=[0,total(n,/cum,/int)]
> IDL> print,indgen(n_elements(inds))-c[inds]
> 0 0
> 1 0 0
> 1 2 3

From the moment I used the where function, I just knew there was a
better way :-).

> For the life of me, I can't remember how to transform n = [1,2,1,4]
> ==> inds = [0,1,1,2,3,3 ,3 ,3] - I spent ages reading the IDL function
> list, but I can't find it...

http://www.dfanning.com/idl_way/chunkindex.html

But Matt knew how to do that.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Get Latitude and Longitude from Tiff files
Next Topic: moxed format file i/o

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

Current Time: Wed Oct 08 14:00:35 PDT 2025

Total time taken to generate the page: 0.00417 seconds