I have the following situation. H12 is an array of dimension (n,k,m) and hessian_lambda is a numeric of length m.
I need to multiply each matrix H12[,,1], H12[,,2], ..., H12[,m] by hessian_lambda[1], hessian_lambda[2], ..., hessian_lambda[m], respectively, and then add the resulting (n,k) matrices. What I am using at the moment is the following code: H <- matrix(0, n, k) for(j in 1:(m)) { H <- H + H12[,,j]*hessian_lambda[j] } Does anybody see a way to speed up this without using loop? (The output needs to be a matrix). Thank you for your time. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.