[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Efficient multiplication by a diagonal matrix
From: |
SANDS |
Subject: |
Re: Efficient multiplication by a diagonal matrix |
Date: |
Thu, 14 Nov 1996 17:41:46 -0400 (EDT) |
Mario Storti writes:
>I found myself repeatedly with the following problem. Given a matrix
>A(n,m) and a vector v(n), I have to multiply each row A(j,:) by
>v(j). This is equivalent to compute:
>
>B = diag(v) * A (1)
>
>Now, for large n, (1) is very inefficient ...
Right, try using "Tony's Trick", it's been around for years.
Assuming v is a column vector (if not do v=v(:);) try
B=v(:,ones(length(v),1)) .* A;
This is a kind-of MATLAB specific thing but I think
it works in octave o.k.
Scott Sands