a newbie question on code efficiency [message #26299] |
Fri, 17 August 2001 19:54 |
gogosgogos
Messages: 15 Registered: July 2001
|
Junior Member |
|
|
Dear group members,
i have a little challenge for you which i stumbled into..
i tried to write a program which takes a 3d array,
sets a cutoff at a certain level and then creates a mask
of all values above that level. the mask has to be 1 and 0.
i came up with this code, but could never get rid of the loop.
any suggestions on how to get rid of the loop?
i would prefer array operators for speed :)
;----------------------------------------------------------- ------
PRO MAKE_MASK
a = dialog_pickfile()
b = READ_BINARY(a, DATA_TYPE=1, DATA_DIMS=[160,256,256])
b_dims = size(b)
x_dim = b_dims[1]
y_dim = b_dims[2]
z_dim = b_dims[3]
cutoff = 180
e = b
for i = 0, (x_dim-1) do begin
for j = 0, (y_dim-1) do begin
for k = 0, (z_dim-1) do begin
if e[i,j,k] lt cutoff then e[i,j,k]=0
if e[i,j,k] ge cutoff then e[i,j,k]=1
endfor
endfor
endfor
; and so on to use the mask further in the program
END
|
|
|