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

Home » Public Forums » archive » Re: 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
Re: initializing arrays [message #49012] Fri, 09 June 2006 11:03 Go to next message
btt is currently offline  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 #49013 is a reply to message #49012] Fri, 09 June 2006 10:48 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
johnadams_1980@yahoo.com writes:

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

Sigh..

array = IntArr(5) + value

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: initializing arrays [message #49066 is a reply to message #49012] Tue, 13 June 2006 15:42 Go to previous message
Marshall Perrin is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Using Windows IDL to access a UNIX database using DLM's
Next Topic: is there a command in IDL like bitget command in matlab?

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

Current Time: Wed Oct 08 13:43:34 PDT 2025

Total time taken to generate the page: 0.00474 seconds