Re: Initialize new variable array with nan or -9999 values [message #87653 is a reply to message #87648] |
Thu, 20 February 2014 17:36   |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Thu, 20 Feb 2014 14:14:54 -0800 (PST), wlandsman wrote:
> For large arrays, there is a speed advantage to using REPLICATE or MAKE_ARRAY in which the array is initialized with the correct value, as opposed to
>
> fltarr(304,336,500) - 9999
>
> in which the array is first initialized with zeros, and then 9999 is subtracted from each element.
Yes, one should think so. But it is not true. "fltarr()-9999" ist
faster than make_array():
IDL> t0=systime(1) &for i=0,9 do a=fltarr(1000,1000,100)-9999.
&print,systime(1)-t0 &help,a
1.8280001
A FLOAT = Array[1000, 1000, 100]
IDL> t0=systime(1) &for i=0,9 do
a=make_array(1000,1000,100,value=-9999.) &print,systime(1)-t0 &help,a
2.7969999
A FLOAT = Array[1000, 1000, 100]
IDL> print,!version
{ x86 Win32 Windows Microsoft Windows 8.0.1 Oct 5 2010 32
64}
Don't ask me why.
Cheers, Heinz
|
|
|