Hello,

I would like to compute a weighted combination of matrices.

I have a number of matrices, arranged in a 3D-array, say:

z = array(rep(1:3,c(9,9,9)),c(3,3,3))

so that z[,,1] is my first matrix, and z[,,2] and z[,,3] the second and 
third one, and a vector of coefficients:

w = rep(1/3,3)

I would like to compute:

w[1]* z[,,1] + w[2]*z[,,2] + w[3]*z[,,3]

I could of course do this using a for() loop, but would like to know if 
there is a way to do it in a "vectorized" manner, or any other way that 
is likely to result in faster computation.

Any hint ?

Thank you very much in advance,

YNOEL

______________________________________________
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.

Reply via email to