M
我也翻译成了R代码,也可以试试
rows<-1000
cols<-10
M1<-matrix(round(rnorm(cols)*100,0),nrow=1)
M2<-matrix(round(rnorm(rows*cols)*100,0),nrow=rows)
result <- matrix(, nrow = rows, ncol = rows)
for(i in 1:rows){
for(j in 1:rows){
result[i,j] = 0
for(k in 1:j){
if(k>ncol(M1)){
rangeA = 0
}
else{
rangeA = M1[1,k]
}
if(j-k+1>ncol(M2)){
rangeB = 0
}
else{
rangeB = M2[i,j-k+1]
}
result[i,j]=result[i,j] + rangeA * rangeB
}
}
}