Home »
Public Forums »
archive »
advise for saving a for-loop
advise for saving a for-loop [message #67991] |
Mon, 14 September 2009 08:52 |
Bernhard Reinhardt
Messages: 26 Registered: October 2008
|
Junior Member |
|
|
Hi,
I don't know if there's a special term for what I'm trying to do:
I have two 2D arrays of the same size (msg_x and msg_y) which contain x-
and y-values. So msg_y consists of rows which contain mainly the same
values and msg_y consists of columns which contain mainly the same
values. But it has to mentioned that values are slightly changing in a
row or column. That's what make's things nasty.
For msg_y it means, it may look like:
1000 1000 1000 1000 [..] 1001 1001 1001 1001 [..] 1002 1002
1001 1001 1001 1001 [..] 1002 1002 1002 1002 [..] 1003 1003
1002 1002 1002 [..] 1003 1003 1003 1003 [..] 1004 1004 1004
I also have two linear arrays li_x and li_y of the same size. I now want
to make a map with the same dimensions of msg_x with a 1 where the
points in the linear arrays match into the pseudo-grid and 0 elsewhere.
Here's how I do it at the moment:
for i=0, N_ELEMENTS(li_x)-1 do begin
ind=WHERE(msg_x eq li_x[i] AND msg_y eq li_y[i])
if ind[0] ne -1 then ligrid[ind] = 1
endfor
The 2-D arrays have sizes of 600x600 or 1800x1800 and the linear arrays
are of size 10000.
This means where has to search 10000 over the two 2D-arrays which takes
some time.
I guess there must be a smarter way to do. I thought about some
solutions involving sort and histogram but so far I couldn't come up
with a solution without for-loops.
I'd be pleased if someone of you could enlighten me.
Regards,
Bernhard
|
|
|
Current Time: Thu Oct 09 06:40:19 PDT 2025
Total time taken to generate the page: 0.24358 seconds