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

Home » Public Forums » archive » Re: multiplication by a diagonal matrix
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: multiplication by a diagonal matrix [message #40810 is a reply to message #40809] Fri, 03 September 2004 05:32 Go to previous messageGo to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
Lorenzo Busetto wrote:
> Hi all,
>
> I have the following problem: given a matrix A(n,m) and a vector of
> weighting factors w(n), i need to multiply each row of the matrix
> A(i,*)by the corresponding weighting factor w(i).
>
> I know that I can simply "transform" the w vector into a diagonal
> matrix with diag_matrix and then multiply it with A (e.g.: result =
> A##diag_matrix(w)), but for large values of n this solution is very
> slow.
>
> Can anybody suggest me a faster approach to solve this problem ?
>
> Thanks in advance for the help,
>
> Lorenzo Busetto
>
> Remote Sensing Lab.
> University of Milano-Bicocca.

You could try (if you *really* want to avoid a FOR loop over the rows):

N=n_elements(w)
ahelp=replicate(1d,N)##w
res=a*ahelp

In the second line, * is much faster than ##, and the first
line is just a 1 by N matrix multiplication, faster than the
N by N you used.


Ciao,
Paolo
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: event_pro for compound widgets
Next Topic: multiplication by a diagonal matrix

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

Current Time: Fri Oct 10 13:01:35 PDT 2025

Total time taken to generate the page: 0.16104 seconds