In [1]:
import numpy as np

In [2]:
# Randomly generate adjacency adjaceny matrix representation
def generateGraph(nPoints, dimension=2):
    points = np.random.sample(size=(nPoints, dimension))
    # Taken from http://stackoverflow.com/questions/32473635/how-do-i-calculate-all-pairs-of-vector-differences-in-numpy
    distances = []
    nodes = []
    for point in points:
        edge_distances = np.linalg.norm(points - point, axis=1)
        to_keep = edge_distances < 0.22
        edge_distances = edge_distances[to_keep]
        distances.append(edge_distances)
        indexes = np.arange(0,nPoints)
        indexes = indexes[to_keep]
        nodes.append(indexes)
    return distances, nodes

In [ ]:
generateGraph(68000, 2)

In [39]:
differences


Out[39]:
array([[ 0.        ,  3.46410162],
       [ 3.46410162,  0.        ]])

In [15]:
points = np.array([[1,2,3], [2,2,2], [7,8,9]])

In [20]:
points - points[0]


Out[20]:
array([[ 0,  0,  0],
       [ 1,  0, -1],
       [ 6,  6,  6]])

In [12]:
result = []
for point in points:
    result.append(np.linalg.norm(points - point, axis=1))


Out[12]:
array([[[ 0,  0,  0],
        [-3, -3, -3],
        [-6, -6, -6]],

       [[ 3,  3,  3],
        [ 0,  0,  0],
        [-3, -3, -3]],

       [[ 6,  6,  6],
        [ 3,  3,  3],
        [ 0,  0,  0]]])

In [ ]: