multiplication by a diagonal matrix [message #40812] |
Fri, 03 September 2004 03:53  |
lbusett
Messages: 9 Registered: March 2004
|
Junior Member |
|
|
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.
|
|
|
Re: multiplication by a diagonal matrix [message #40927 is a reply to message #40812] |
Wed, 08 September 2004 06:33  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Lorenzo Busetto writes:
> Well, when I posted my message I'd never expected to increase the
> speed 800000 times ! Can it be possible ?
You haven't been hanging out very long on the IDL
newsgroup. It's not only possible, it is the humdrum
around here. :-)
http://www.dfanning.com/code_tips/slowloops.html
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
|
|
|