Let's assume that I have a vector
r <- rnorm(4)
and a matrix W
of dimension 20000*200 for example:
W <- matrix(rnorm(20000*200),20000,200)
I want to compute a new matrix M
of dimension 5000*200 such that m11 <- r%*%W[1:4,1]
, m21 <- r%*%W[5:8,1]
, m12 <- r%*%W[1:4,2]
etc. (i.e. grouping rows 4-by-4 and computing the product).
What's the optimal (speed,memory) way of doing this?
Thanks in advance.
This seems to run fastest for me:
array(r %*% array(W, c(4, 20000 * 200 / 4)), c(5000, 200))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With