2018-10-03 18:59:01 +00:00
|
|
|
# from: http://jakevdp.github.com/blog/2012/08/24/numba-vs-cython/
|
|
|
|
# setup: import numpy as np ; X = np.linspace(0,10,200).reshape(20,10)
|
|
|
|
# run: pairwise_loop(X)
|
2018-10-03 12:38:27 +00:00
|
|
|
|
2018-10-03 18:59:01 +00:00
|
|
|
# pythran export pairwise_loop(float [][])
|
2018-10-03 12:38:27 +00:00
|
|
|
|
|
|
|
import numpy as np
|
2018-10-03 18:59:01 +00:00
|
|
|
|
|
|
|
|
2018-10-03 12:38:27 +00:00
|
|
|
def pairwise_loop(X):
|
|
|
|
M, N = X.shape
|
2018-10-03 18:59:01 +00:00
|
|
|
D = np.empty((M, M))
|
2018-10-03 12:38:27 +00:00
|
|
|
for i in range(M):
|
|
|
|
for j in range(M):
|
|
|
|
d = 0.0
|
|
|
|
for k in range(N):
|
2018-10-03 18:59:01 +00:00
|
|
|
tmp = X[i, k] - X[j, k]
|
2018-10-03 12:38:27 +00:00
|
|
|
d += tmp * tmp
|
2018-10-03 18:59:01 +00:00
|
|
|
D[i, j] = np.sqrt(d)
|
2018-10-03 12:38:27 +00:00
|
|
|
return D
|