Skip to content
Prev 314280 / 398502 Next

efficiently multiply different matrices in 3-d array with different vectors?

Hello,

I have been wondering of an efficient way to do this:

I have an n x m x p array Z and a p x n matrix Y.

I want to multiply each of the n matrices with the corresponding column
vector of Y.

In other words, I am wanting to matrix multiply: 

Z[i, ,] %*% Y[, i]

which will give me a (two-dimensional) array or matrix of dimension n x
p with the i'th row storing the above.

Any pointers on an efficient way of doing this? I considered using
apply, but was not successful. 

Many thanks again and best wishes,
Ranjan