Skip to content

Instantly share code, notes, and snippets.

@faroit
Created October 11, 2016 21:35
Show Gist options
  • Save faroit/af965ab6fa5a3fb4ca12fdbcb8c5a93e to your computer and use it in GitHub Desktop.
Save faroit/af965ab6fa5a3fb4ca12fdbcb8c5a93e to your computer and use it in GitHub Desktop.
pairwise distance comparisons

PYTHON

import scipy.spatial.distance as dist
import numpy as np
import timeit

X = np.random.random((1000, 1000))

def run():
    c = dist.cdist(X, X, 'euclidean')
    return c

times = timeit.Timer(run).timeit(number=100)

print times

Elapsed time: 108.59s

MATLAB

X = rand(1000,1000);
tic;

for n = 1:100
   c = pdist2(X, X, 'euclidean');
end
toc

Elapsed Time: 108.66s

Julia

using Distances

tic()
X = rand(1000, 1000)
for i = 1:100
    R = pairwise(Euclidean(), X, X)
end
toc()

Elapsed Time: 5.69s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment