r - How to do elementwise multiplication of big matrix with vector very fast? -


i want elementwise multiplication of vector every rows of big binary matrix. length of vector equal number of columns of matrix. have implemented using loop follow, it's slow. knows solution speed up?

a<-c() m # binary matric w<-matrix(0, nrow=nrow(m), ncol=ncol(m)) w<-data.frame(w) for(i in 1:nrow(w)){ w[i,]<-m[i,] * } 

use vector recycling, since matrices filled columns, need transpose:

t(t(m) * v) 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

python - RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK -