Re: all combinations from two lists [message #75651] |
Mon, 14 March 2011 13:20 |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
Never mind, figured it out. Using HIST_ND makes it a lot easier to think about. It doesn't actually require much modification from the basic histogram-of-histogram approach:
maxid = max([list1, list2])
h1 = histogram(list1, min=0, max=maxid, reverse=ri1)
h2 = histogram(list2, min=0, max=maxid, reverse=ri2)
hnd = hist_nd(transpose([[h1],[h2]]), min=[0,0], 1, reverse_indices=rind)
hndsize = size(hnd, /dimen)
for k1=1L, hndsize[0]-1 do begin
for k2=1L, hndsize[1]-1 do if hnd[k1,k2] gt 0 then begin
knd = k1 + k2 * hndsize[0]
targ = [hnd[knd], k1, k2]
these_bins = rind[rind[knd]: rind[knd+1]-1]
these_1 = ri1[ri1[rebin(these_bins,targ,/samp)] + $
rebin(lindgen(1,k1,1),targ,/samp)]
these_2 = ri2[ri2[rebin(these_bins,targ,/samp)] + $
rebin(lindgen(1,1,k2),targ,/samp)]
...do stuff with these_1 and these_2...
endif
endfor
-Jeremy.
|
|
|