I recently switched from Matlab to Python. While converting one of my lengthy codes, I was surprised to find Python being very slow. I
Matlab
Python
I got ~5x speed improvement over the meshgrid solution using only broadcasting:
def exampleKernelD(M, x, N, y): return np.sqrt((x[:,1:] - y[:,1:].T) ** 2 + (x[:,:1] - y[:,:1].T) ** 2)