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
Post a Comment