1

I would like to create a distance matrix from a pair of coordinates. At the moment I'm only using pandas. What I have managed to do so far is the following

data = pd.read_csv('coordinates.txt', sep='\t')
df=[]
L=[]
D=[]
Y=[]
for i in range(data.shape[0]):
    distanceMatrix=[]
    for k in range(data.shape[0]):
        L=float(math.sqrt((data['Easting'][i]-data['Easting'][k])**2+(data['Northing'][i]-data['Northing'][k])**2))
        distanceMatrix.append(L)
    name='A'+str(i)
    df=pd.DataFrame(data=distanceMatrix)
    df.rename(columns={0: name}, inplace=True)
    D.append(df)   
Y=pd.concat(D, axis=1)

This works fine but I was thinking that there should be way of reducing the number of variables.

Thanks

ardms
  • 158
  • 4
  • 16
  • possible duplicate of [Efficiently Calculating a Euclidean Distance Matrix Using Numpy](http://stackoverflow.com/questions/22720864/efficiently-calculating-a-euclidean-distance-matrix-using-numpy) – pacholik Sep 16 '15 at 09:17

0 Answers0