from functools import reduce
def binomial_coefficient(n, k):
    return int(reduce(mul, (Fraction(n - i, i + 1) for i in range(k)), 1))

def pairwise_displacements(a):
    n = a.shape[0]
d = a.shape[1]
c = binomial_coefficient(n, 2)
out = numpy.zeros((c, d))
l = 0
r = l + n - 1
for sl in range(1, n):
    out[l:r] = a[:n - sl] - a[sl:]
l = r
r += n - (sl + 1)
return out
Векторы попарных перемещений среди множества точек