Hi Everyone I am trying to write code (using python 2) that returns a matrix that contains the distance between all pairs of rows. Below is an implementation that I have written. It works as expected but can get very slow as the number of rows gets large. Hence I was wondering if anyone has any suggestions as to how the code can be made more efficient for large number of rows.
Thanks in advance
def gendist(x,alpha=2):
(n,p) = x.shape
len = 0
for ii in range(1,n):
len = len + ii
d = np.empty((len,p))
ind = 0
for ii in range(0,n):
for jj in range(1,n):
if ii < jj:
d[ind,] = (x[ii,]-x[jj,])**alpha
ind = ind + 1
return d