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

Home » Public Forums » archive » Re: Fast matrix filling in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Fast matrix filling in IDL [message #13791 is a reply to message #13788] Fri, 11 December 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Timm Weitkamp (weitkamp@my-dejanews.com) writes:

> What is the fastest way of filling a matrix with identical
> column vectors in IDL?
>
> More precisely, if A is a float matrix (m x n) and V is
> a vector with m elements, is there a faster way than
>
> FOR i=0,n-1 DO A[*,i]=V ?

I don't know about "fastest", but

vector = Replicate(1, n)
array = V ## vector

is about 5 times faster for a 1000 by 500 array.
Here is my example program:

************************************************************ *
PRO TEST

array = Fltarr(1000, 500)
v = RandomU(seed, 1000)

time = systime(1)
FOR i=0,500-1 DO array[*,i] = v
Print, 'Time for Loop: ', systime(1) - time

time = systime(1)
vector = Replicate(1, 500)
array = v ## vector
Print, 'Time for Matrix Operations: ', systime(1) - time
END
************************************************************ *

And the results:

IDL> test
Time for Loop: 0.10000002
Time for Matrix Operations: 0.019999981

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Progamming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: probability scale on 2D line plot?
Next Topic: Re: GEO TIFF read/write ?

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

Current Time: Sat Oct 11 21:09:12 PDT 2025

Total time taken to generate the page: 1.52186 seconds