def distances_numba_array(cluster):
# Original: diff = cluster[:, np.newaxis, :] - cluster[np.newaxis, :, :]
# Since np.newaxis is not supported, we use reshape to do this
diff = (cluster.reshape(cluster.shape[0], 1, cluster.shape[1]) -
cluster.reshape(1, cluster.shape[0], cluster.shape[1]))
mat = (diff * diff)
# Original: mat = mat.sum(-1)
# Since axis argument is not supported, we write the loop out
out = np.empty(mat.shape[:2], dtype=mat.dtype)
for i in np.ndindex(out.shape):
out[i] = mat[i].sum()
return np.sqrt(out)
评论列表
文章目录