Fast computation of pairwise array element differences [message #78636] |
Sun, 04 December 2011 08:28 |
erik
Messages: 2 Registered: June 1993
|
Junior Member |
|
|
Hi folks,
I have the following problem that I want to solve with IDL, but do not
know how:
I have a n^2 array (2D) with some arbitrary numercial data in it and a
lengthscale L (let's say a certain number of cells smaller than n).
What I want to do now is to compute all possible differences of
elements in this 2D array that are L cells far away from each other,
but *without using loops*!
Of course, I could do the following (in pseudo code):
------
diff = 0.d
FOR x = 0, n do begin
FOR y = 0, n do begin
- Take array element (x, y)
- Look for all cells that are L cells away from cell (x, y)
(e.g. in a ring arround (x, y) with radius of L cells)
- compute all differences from (x, y) to the other cells in a
radius of L
- Summ differences up in a variable diff
- continue with next array element and compute next differences
and so on...
ENDFOR
ENDFOR
------
This is an easy mathematical operation. Nevertheless, for an array of
500 x 500 it takes about hours to step through all the looping
processes and to calculate the sum of really all possible differences
on a lengthscale of L cells...
Does someone have another idea how to avoid the loops in this case and
to compute all possible differences in such an array very easily?
Thank you very much!
Kind regards,
Erik
|
|
|