Re: Faster approach for total(data,dimension) possible? [message #67071 is a reply to message #67070] |
Wed, 24 June 2009 04:19  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Jun 24, 3:54 am, chris <rog...@googlemail.com> wrote:
> Hi,
> i'm looking for a faster approach to do the following:
>
> data=rebin(dist(100),100,100,50,/sample)
> mask=total(data,3) gt 0.
>
> Depending on the size of data and on the hardware of the client the
> code above runs too slow for me. I'd like to find all pixels in a
> hyperspectral application, which bands are not zero. The result should
> be a mask with the same 2D-dimensions as original data for further
> processing.
My first thought was to use ARRAY_EQUAL rather than TOTAL since
ARRAY_EQUAL(im,0) will stop computations as soon as a non-zero element
is found. But as far as I know, ARRAY_EQUAL can only return a
scalar argument, which means that one would have to loop over each
element of the output mask. Ugh.
But if we are forced to use TOTAL, there is no need for a double
precision computation. I found a significant speedup by replacing
the second line with
mask = total(data,3,/integer) GT 0
I also found a smaller speedup with the following code, which is based
on the theory that mathematical operations are always quickest on byte
data.
mask = total(data GT 0,/preserve_type,3) GT 0
-Wayne
|
|
|