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