Re: Search single column of array - removing nasty loop [message #78551 is a reply to message #78538] |
Tue, 29 November 2011 04:49   |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
On Nov 29, 1:40 pm, Yngvar Larsen <larsen.yng...@gmail.com> wrote:
> (1) The original loop is better like this.
>
> FOR k = 0, 359 DO FOR j = 0, 5 DO FOR i=0,1 DO $
> IF (total(array[i,j,k,*]) gt 0) THEN array[i,j,k,*] = 0
Bug fix. Should be:
FOR k = 0, 359 DO FOR j = 0, 5 DO FOR i=0,1 DO $
IF (total(array[i,j,k,*] eq 0) gt 0) THEN array[i,j,k,*] = 0
> (3) Since you are operating only on one dimension, it should really be
> the first one for efficiency reasons. So it is better to actually keep
> the data stored that way. If that is not possible, a transpose before
> and after the operation might help you:
[...]
> for ii=0L, nrow-1 do if (total(A[*,ii] eq 0) gt 0) then A[*,ii] = 0
Another bugfix. Should of course be
for ii=0L, nrow-1 do if (total(array[*,ii] eq 0) gt 0) then
array[*,ii] = 0
--
Yngvar
|
|
|