I'm working on something which requires me to calculate the elements of a large square matrix repeatedly. The process involves reading data stored in another matrix, and then calculating the matrix elements. Presently I am using a double for loop to do this.
library(matrixcalc)
data <- matrix(nrow=3,ncol=1000)
for(x in 1:ncol(data)){
for(y in 1:ncol(data)){
matrix[x,y]=exp(-entrywise.norm(data[,x]-data[,y],2))
}
}
The problem is that this is extremely slow since my matrix is very large. What is the fastest alternative to this procedure?