Re: initializing arrays [message #49012] |
Fri, 09 June 2006 11:03  |
btt
Messages: 345 Registered: December 2000
|
Senior Member |
|
|
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
Ben
|
|
|
|
Re: initializing arrays [message #49066 is a reply to message #49012] |
Tue, 13 June 2006 15:42  |
Marshall Perrin
Messages: 44 Registered: December 2005
|
Member |
|
|
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
|
|
|