Say I have two three dimensional arrays and I would like the sum of the products of the arrays based on one of the indices. What I would like is that sum in the the last line of the example code below. I know I can use a loop but I'd like to do this in an efficient way, hoping that there is some R function that does something like this. Any help would be greatly appreciated.
a <- array(1:12, dim=c(3, 2, 2))
b <- array(1, dim=c(3, 2, 2))
a[1, , ] %*% t(b[1, , ]) + a[2, , ] %*% t(b[2, , ]) + a[3, , ] %*% t(b[3, , ])