[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: late Re: A Simple Matrix Construction Question

From: Ted Harding
Subject: Re: late Re: A Simple Matrix Construction Question
Date: Thu, 06 Feb 2003 09:18:05 -0000 (GMT)

On 05-Feb-03 David Bateman wrote:
> If this is what you want to do, why not do for example
> m = 4;
> n = 5;
> y = rand(1,n);
> x = y(ones(m,1),:);
> where x will now be a m by n matrix with m copies of y,
> one per row. Indexing should definitively be more
> computationally efficient than doing a matrix multiply
> which is O(n^3).

In this case, I think pre-multiplication by a column
vector of 1s is slightly quicker, though not much.

With y already set up as above:

octave:9> tic;for i=1:50000,x = y(ones(m,1),:);endfor,toc
ans = 7.4079

octave:10> tic;for i=1:50000,x = ones(m,1)*y;endfor,toc
ans = 6.0705


E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 167 1972
Date: 06-Feb-03                                       Time: 09:18:05
------------------------------ XFMail ------------------------------

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]