Re: help with chunk indexing [message #54641] |
Mon, 02 July 2007 05:42  |
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   |
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  |
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.
|
|
|