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

Home » Public Forums » archive » Re: help with sorting vector elements in to subarrays
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 sorting vector elements in to subarrays [message #80217] Tue, 22 May 2012 05:27 Go to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
If you know these line groups in advance, and you just want to label the groups, you could use something like:

zz = [5,6,9,10,11]

n_groups=2
group=[0,0,1,1,1]

for i=0,n_groups-1 do begin
q=where(group eq i)

...some operation on zz[q]...
endfor

If you don't know in advance, maybe you can create this group vector out of your amp array. If amp is a float representing amplitude, I can't see how you'd do that, but I'm just guessing what you have.

Greg
Re: help with sorting vector elements in to subarrays [message #80223 is a reply to message #80217] Mon, 21 May 2012 13:22 Go to previous messageGo to next message
Tito is currently offline  Tito
Messages: 16
Registered: March 2012
Junior Member
> You're not making much sense... How does zz=[5,6,9,10,11] sort into
> zz1=[5,6] and zz2=[9,10,11]? Are you just taking the first two and
> last three elements?
>
> Russell
>
> But, yes, uniq() is probably going to help you. Just remember, uniq
> only works correctly on arrays which are sorted!

Dear Greg and Russel,

I know the Uniq() routine. I try it several times with no success.

I am trying to select spectral lines with the same depths. It is a very long story why they are with the same depths....
As you can imagine amp[i] has a different values ranging from 0 to 1 for each wavelength thats why I cant Sort() them (at least I don't know how)


zz=[5,6,9,10,11] in particular 5,6 and 9,10,11 are the indexes of very close lines in the spectra and they are basically blended. Thats why I want to take them out from the array make a multigauss fit and the result Gaussian I will pass it again as one gaussian(Lorentzian actually) sum of the gaussians of line[5,6] or line[9,10,11]

this is just a simple example sometimes I have 4 close lines or 3-4 pairs.

with the above code [ugly I admit] I am taking out the closed lines in an array

zz=[5,6,9,10,11] but then i need to split it to zz1=[5,6] and zz2=[9,10,11]
this is all that i need in order to start the multigaussian fitting automatically.

I have huge amount of data and I want this to be automatic.

I am sure there is an easy way but this somehow is working and I am happy.

Anyway I will continue trying... any feed back is more than welcome.

Trifon
Re: help with sorting vector elements in to subarrays [message #80227 is a reply to message #80223] Mon, 21 May 2012 12:16 Go to previous messageGo to next message
Russell Ryan is currently offline  Russell Ryan
Messages: 122
Registered: May 2012
Senior Member
On May 21, 10:33 am, Trifon Trifonov <tito_trifo...@abv.bg> wrote:
> Hallo!
>
> I have this vector:  zz = [5,6,9,10,11]
>
> Anybody can tell me how I can sort it like zz1 = [5,6], zz2 =[9,10,11]?
>
> Here is the code:
>
> zz =[]
> f=indgen(n_elements(amp))
>
> ;;I have amp[i] on witch some of the elements are identical.
> ;I need to take this [i]indexies and
> ;1-st to take it out
> ;2nd to write it to another array [sub arrays]
>
> for i=0L, n_elements(amp)-1 do begin
>  a = where(amp[i] eq amp ,count)
>  if count gt 0.0 then begin
>   if n_elements(a) gt 1 then begin
>     zz = [zz,i]
>   endif
>  endif
> endfor
>
> if n_elements(zz) ne 0.0 then begin
>  match2,f,zz,subf,subzz
>  f[subzz] = -1
>  f = f[where(f[*] NE -1)]
> endif
>
> zz = Long[5]
>            4           5           9          10          11
>
> f = Int[13]
>        0       1       2       3       6       7       8      12      13      14
>       15      16      17
>
> All the best,
> Trifon

You're not making much sense... How does zz=[5,6,9,10,11] sort into
zz1=[5,6] and zz2=[9,10,11]? Are you just taking the first two and
last three elements?

Russell

But, yes, uniq() is probably going to help you. Just remember, uniq
only works correctly on arrays which are sorted!
Re: help with sorting vector elements in to subarrays [message #80233 is a reply to message #80227] Mon, 21 May 2012 08:54 Go to previous messageGo to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
I can't follow exactly what you want to do, but whatever it is, I think you'd find the uniq() function would make it simpler.

Greg
Re: help with sorting vector elements in to subarrays [message #80298 is a reply to message #80217] Wed, 23 May 2012 08:35 Go to previous messageGo to next message
Tito is currently offline  Tito
Messages: 16
Registered: March 2012
Junior Member
On Tuesday, May 22, 2012 2:27:58 PM UTC+2, (unknown) wrote:
> If you know these line groups in advance, and you just want to label the groups, you could use something like:
>
> zz = [5,6,9,10,11]
>
> n_groups=2
> group=[0,0,1,1,1]
>
> for i=0,n_groups-1 do begin
> q=where(group eq i)
>
> ...some operation on zz[q]...
> endfor
>
> If you don't know in advance, maybe you can create this group vector out of your amp array. If amp is a float representing amplitude, I can't see how you'd do that, but I'm just guessing what you have.
>
> Greg

Greg I will try it! But yes amp[i] is a float representing amplitude. For now I exclude this blended lines but I will definitely need them later. I will probably make another ugly loop that will handle with that ( I hope) I was just searching for a simple method that might separate this trivial vector to neighboring sub arrays but i guess it is not that easy...
I will write when I get solution. I have something in mind.

Trifon
Re: help with sorting vector elements in to subarrays [message #80301 is a reply to message #80298] Thu, 31 May 2012 05:07 Go to previous messageGo to next message
Tito is currently offline  Tito
Messages: 16
Registered: March 2012
Junior Member
OK I tried and I fail.... I did this:

zz = []
f=indgen(n_elements(amp)) ;; (f=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])

for i=0L, n_elements(amp)-1 do begin
a = where(amp[i] eq amp ,count)
if count gt 0.0 then begin
if n_elements(a) gt 1 then begin
zz = [zz,i] ;; (zz =[3,4,6,7,8,9,10])
endif
endif
endfor

if n_elements(zz) ne 0.0 then begin
match2,f,zz,subf,subzz
f[subzz] = -1
f = f[where(f[*] NE -1)] ;; (f = [0,1,2,5,11,12,13,14,15]) So far great!

;;amp[zz] = [0.5538, 0.5538, 0.5524, 0.5524, 0.5524, 0.1255, 0.1255]

ss = unique(amp[zz],count) ;; (ss=[0.5538, 0.5524, 0.1255])
dd = dblarr(n_elements(ss),20)*0-1
for i = 0L , n_elements(ss)-1 do begin
a = where(ss[i] eq amp,count)
dd[i,a] = a
endfor
endif

;; Now dd = Double[3, 20]
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
3.0000000 -1.0000000 -1.0000000
4.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 6.0000000 -1.0000000
-1.0000000 7.0000000 -1.0000000
-1.0000000 8.0000000 -1.0000000
-1.0000000 -1.0000000 9.0000000
-1.0000000 -1.0000000 10.000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000
-1.0000000 -1.0000000 -1.0000000


And the question... how can I remove the '-1' and to get 3 diferent vector [3,4] [6,7,8] and [9,10] ???

thank you !
Re: help with sorting vector elements in to subarrays [message #80450 is a reply to message #80301] Thu, 31 May 2012 05:36 Go to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
Would this do it?

for i = 0L, n_elements(ss)-1 do print,where(ss[i] eq amp)

greg
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: VM Save File Problem
Next Topic: Re: help with mathematics

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

Current Time: Wed Oct 08 13:54:47 PDT 2025

Total time taken to generate the page: 0.15223 seconds