Question: I want to generate a matrix that stores the distance between every point with every other point. I want to be able to access this distance value in the matrix using the two coordinates.

As in the image below, I want to be able to access the distance using the points as the index.

matrix[point a, point b] = distance between two points

[![The matrix with the euclidean distance between points](https://i.stack.imgur.com/waENP.jpg)](https://i.stack.imgur.com/waENP.jpg)

Answer: 
One solution is to use the `pandas` module. 

* You can define column and index name with "*points coordinates*".
* Fill the data using the [`scipy.spatial.distance.cdist`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html)
* Access all the distances from one point using `df["[x, y]"]`
* Access a specific distance using [`iloc`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.iloc.html) on a column

---

**Full code + illustration**

```
# import modules
import pandas as pd
from scipy.spatial.distance import cdist

# input points
points = [[1, 2], [2, 3], [3, 4], [5, 6], [9, 10]]

# Create dataframe
df = pd.DataFrame(cdist(points, points),
     columns=[str(p) for p in points],
     index=[str(p) for p in points])
print(df)
#             [1, 2]    [2, 3]    [3, 4]    [5, 6]    [9, 10]
# [1, 2]    0.000000  1.414214  2.828427  5.656854  11.313708
# [2, 3]    1.414214  0.000000  1.414214  4.242641   9.899495
# [3, 4]    2.828427  1.414214  0.000000  2.828427   8.485281
# [5, 6]    5.656854  4.242641  2.828427  0.000000   5.656854
# [9, 10]  11.313708  9.899495  8.485281  5.656854   0.000000

# select column "[2, 3]"
print(df["[2, 3]"])
# [1, 2]     1.414214
# [2, 3]     0.000000
# [3, 4]     1.414214
# [5, 6]     4.242641
# [9, 10]    9.899495

# get distance between point [2 3] and [1 2]
print(df["[2, 3]"].loc["[1, 2]"])
# 1.4142135623730951

```

Hope that helps
If you request to solve it in numpy, you can use the [where](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) clause. Here a sample:

```
import numpy as np
X = np.array([[1,2],[2,3],[3,4],[5,6],[9,10]])
distance_matrix = np.zeros((X.shape[0],X.shape[0]))
# distance matrix
distance_matrix[np.where(X==[1,2])[0][0],np.where(X==[1,2])[0][0]] = 0
distance_matrix[np.where(X==[1,2])[0][0],np.where(X==[2,3])[0][0]] = np.linalg.norm(np.array([1,2]) - np.array([2,3]))
distance_matrix[np.where(X==[2,3])[0][0],np.where(X==[1,2])[0][0]] = np.linalg.norm(np.array([1,2]) - np.array([2,3]))

```