Rebin/Reform/Histogram [message #72650] |
Tue, 21 September 2010 05:01 |
Mrunmayee
Messages: 24 Registered: May 2009
|
Junior Member |
|
|
1. I have 2 vectors t2 and t2 of size nv each.
2. I have 2 matrices, w1 and w2, of sizes nvxn1 and nvxn2 resp.
(Following IDL notation so nv cols and n1/n2 rows).
3. I need to take each row of w1, multiply (element-wise) to each row
of w2. So effectively I have n1*n2 number of multipled rows.
4. Each of these rows needs to be matrix-multiplied by (t1-t2)^2. So
that I want to end up with n1xn2 matrix (say SF).
5. Independently I have another n1xn2 matrix of distances (D). I need
above matrix as a function of distances from distance matrix. That is,
SF[i,j] is value at D[i,j]. I want D histogrammed, put SF in the same
bins by using reverse_indices and get average value of SF
corresponding to each distance bin.
6. Then I need to repeat the process for a total of 524 t's pair-wise.
So above t1, t2 are chosen at random from 524 t's just to start the
problem. For each of these, n1/n2 can vary from ~100 to ~1500.
So far:
SF = FltArr(n1,n2)
dt = (t1-t2)^2
for i = 0, n1-1 do begin
w = rebin(w[*,i], nv, n2) ; Makes nvxn2 matrix
p = w*w2 ; Performs number 3 above.
SF[i,*] = dt # p
endfor
Improvization (?):
temp = reform(w1, nv, 1, n1) ; Copies each row on separate planes.
w1_3d = rebin(temp, nv, n2, n1)
But I am not aware how I can use this (trying to eliminate the for
loop, you see) for the step calculating 'p' and hence SF.
So questions:
1. Is there a way I can eliminate the for loop? I am not THAT averse
to them anyway. But I would like to know anyway.
2. How can I scale the problem to 524*523/2 number of pairs of t's?
I tried to be consise and explanative at the same time, so do ask me
if I have goofed up.
Thanks.
(And for someone who is using IDL for, like n years, I am resorting to
rebin/reform/histogram only NOW. So to get to this for loop, it took
me 3 weeks. I don't think my collaborator is very happy with that... I
just think I have casted my solutions in IDL mould and they are nice.
I would go in details of the physics/statistics behind it, but maybe
later.. Let's at least get the ball rolling.)
Thanks.
|
|
|