0
我中的R大的正方形矩阵:- [R计算大NOR矩阵
norMat <- matrix(NA, nrow=1024, ncol=1024)
这个空矩阵需要填充了所有矩阵索引对所有等于比特的总和。
所以我需要计算的逻辑NOR为i
(rowIndex位置)和j
(colIndex)和求和的结果,例如:
sum(intToBits(2)==intToBits(3))
Currenty,我有这个功能,其填埋所述矩阵:
norMatrix <- function()
{
matDim=1024
norMat <<- matrix(NA, nrow=matDim, ncol=matDim)
for(i in 0:(matDim-1)) {
for(j in 0:(matDim-1)) {
norMat[i+1,j+1] = norsum(i,j)
}
}
return(norMat)
}
而这里的norsum
功能:
norsum <- function(bucket1, bucket2)
{
res = sum(intToBits(bucket1)==intToBits(bucket2))
return(res)
}
这是填充矩阵的有效解决方案吗? 因为在我的机器上,这个过程需要5分钟以上,所以我很怀疑。
Thx,真是巨大的加速! – juxeii