comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » initializing arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
initializing arrays [message #49014] Fri, 09 June 2006 10:44 Go to next message
johnadams_1980 is currently offline  johnadams_1980
Messages: 3
Registered: June 2006
Junior Member
Hi All,

How do you initialize an array to a specific value without using a for
loop?

Thanks,
KL
Re: initializing arrays [message #49050 is a reply to message #49014] Wed, 14 June 2006 15:10 Go to previous message
biophys is currently offline  biophys
Messages: 68
Registered: July 2004
Member
On a 1GB 3.0GHZ linux machine, the 3rd method is much faster if the
array size is small(eg smaller than fltarr(300,300)). otherwise, the
other two methods are faster(about twice as fast). The performance of
replicate and make_array are always close. I am not sure if it holds
for other platforms.-bp

Marshall Perrin wrote:
> Ben Tupper <btupper@bigelow.org> wrote:
>> johnadams_1980@yahoo.com wrote:
>>> Hi All,
>>>
>>> How do you initialize an array to a specific value without using a for
>>> loop?
>>>
>>> Thanks,
>>> KL
>>>
>> You have choices...
>>
>> arr = REPLICATE(7.0, [32,5])
>>
>> arr = MAKE_ARRAY([32,5], VALUE = 7.0)
>>
>> arr = FLTARR(32,5) + 7.0
>
> And somewhat oddly, all three of these seem to be about equal in
> execution speed for me (tested on a Mac G4 creating a [1000,10000]
> array of floats filled with 7s). I would've predicted the third one
> to be substantially slower due to all thos the additions, but it
> doesn't seem to be. Maybe the IDL compiler is doing something clever
> under the hood? (Which is good news, anyway, since that's the one I use
> most often myself!)
>
> - Marshall
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: GDL does not work properly
Next Topic: Re: itk

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:14:08 PDT 2025

Total time taken to generate the page: 0.00674 seconds