Calculating column-wise dot product between two matrices
问题 I would like to determine the dot product between the i th column in one matrix and the i th column in a second matrix. The end result will be an array containing i dot products. Here is a reproducible example of what I want to do: #Generate two matrices with 10 columns each with 5 rows (thus i in this case is 10) m1 <- replicate(10, rnorm(5)) m2 <- replicate(10, rnorm(5)) #Inefficiently calculate dot product of ith column in m1 with ith column in m2 d1 <- t(m1[,1]) %*% m2[,1] d2 <- t(m1[,2])