New answers tagged

1

I think you could move the where function out of the loop: dists = np.empty((3, a.shape[1] * b.shape[1])) for i in range(3): dists[i, :] = cdist(a[i, :].reshape(-1, 1), b[i, :].reshape(-1, 1), 'cityblock').reshape(-1) dists = np.where(dists > half_s[..., None], dists - s[..., None], dists) ...


Top 50 recent answers are included