Re: [R] Multiply a 3D-array by a vector (weighted combination of matrices)

2007-10-17 Thread Robin Hankin
Hi you need the tensor library: > library(tensor) > z <- array(runif(27),rep(3,3)) > w <- runif(3) > w[1]* z[,,1] + w[2]*z[,,2] + w[3]*z[,,3] [,1] [,2] [,3] [1,] 1.2700333 1.1920113 0.8015904 [2,] 0.5175217 0.7808569 0.6306053 [3,] 0.8386015 0.6143882 0.6382314 > tens

[R] Multiply a 3D-array by a vector (weighted combination of matrices)

2007-10-17 Thread Yvonnick NOEL
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