On Sun, 2015-09-27 at 13:43 +0200, Samuel Gougeon wrote: > 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)))
"Otherwise it's out of memory for usual machine" Meaning, he tried that, and it didn't work. So he does what DOES work, which is diag(sparse(v)) * A This makes the matrix on the left sparse, with a populated diagonal and all the rest zeros (presumably v is fully populated). And, as David has discovered experimentally, it does not run him out of stack space. -- Tim Wescott www.wescottdesign.com Control & Communications systems, circuit & software design. Phone: 503.631.7815 Cell: 503.349.8432 _______________________________________________ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users