[Scilab-users] multiple element by element between large matrix and vector

Samuel Gougeon sgougeon at free.fr
Sun Sep 27 13:43:03 CEST 2015


Hi David,

Le 27/09/2015 12:53, David Chèze a écrit :
> Hi all,
>
> I was wondering what are the possibilities to do a product element by
> element between a matrix A (m rows ,n columns)and a vector (let say column
> vector v (m elements) ): I want each element of each column of A to be
> multiplied by each element of v at the same row. What I'm using for now is a
> product by a diagonal matrix based on v. For large matrix in data
> manipulation (typ. 100000 rows), it's necessary to use sparse to allocate
> better the diag matrix otherwise it's out of memory for usual machine.
> So i'm using --> diag(sparse(v)) * A
>
> Have you best practise to share on this topic ?
.
I am not sure to catch what you want to do, noticeably what is the 
format of the result you expect.
AFAIU, i would do
A .* (v*ones(1,size(A,2)))

Samuel




More information about the users mailing list