[R] Help with multidimensional array

Giuseppe neox86 at gmail.com
Tue Mar 29 01:10:06 CEST 2011


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.



More information about the R-help mailing list