This paste expires on 2023-06-20 08:45:35.334053. Repaste, or download this paste. . Pasted through web.

import numpy as np
X = rand.rand(10, 2)    
dist_sq = np.sum((X[:, np.newaxis, :] - X[np.newaxis, :, :]) ** 2, axis=-1)
differences = X[:, np.newaxis, :] - X[np.newaxis, :, :]                 # for each pair of points, compute differences in their coordinates
sq_differences = differences ** 2                  # square the coordinate differences
dist_sq = sq_differences.sum(-1)          # sum the coordinate differences to get the squared distance
dist_sq.shape
---------
output:
(10, 10)
Filename: None. Size: 501b. View raw, , hex, or download this file.