【发布时间】:2016-04-12 22:28:59
【问题描述】:
我想确定一个矩阵中第 i 列与第二个矩阵中第 i 列之间的点积。最终结果将是一个包含 i 点积的数组。
这是我想做的一个可重复的例子:
#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]) %*% m2[,2]
...
d10 <- t(m1[,10]) %*% m2[,10]
#End with all dot products in array
d.final <- c(d1, d2, d10)
我们将不胜感激!
肯
【问题讨论】:
-
@user20650 啊,我误读了他的 qn。将删除评论
标签: r matrix matrix-multiplication dot-product