0
我想知道如何使用点积。R中的矩阵点积
b = matrix(1:70, ncol=7)
g= matrix(1:48, ncol=6)
resulta = matrix(0,6,7)
for (c in 1:ncol(b)){
for (i in 1:ncol(g)){
resulta[i,c] <- sum((g[,i]) * (b[,c]))
}
}
警告消息:
1: In (g[, i]) * (b[, c]) :
longer object length is not a multiple of shorter object length
2: In (g[, i]) * (b[, c]) :
longer object length is not a multiple of shorter object length
...........................共计42个一样消息
先生,您要乘以不同尺寸''10x7' 8x6' metrices。在每个循环中有10个元素的向量乘以8个元素的向量。此外,要正确地做到这一点,应该使用矩阵乘法运算符而不是循环'%*%'。希望这将有助于http://my.ilstu.edu/~wjschne/442/MatrixAlgebraInR.html#(1) – Gonzo