height = 512
scalar1 = 1
scalar2 = 2
a = np.random.random((height, width, 3))
tmp = np.zeros((height, width))
for i in range(width):
    for j in range(height):
        tmp[j, i] = np.sqrt((scalar1 - a[j, i, 1]) ** 2 + (scalar2 - a[j, i,
            2]) ** 2)
tmp2 = np.sqrt((scalar1 - a[:, :, (1)]) ** 2 + (scalar2 - a[:, :, (2)]) ** 2)
np.allclose(tmp, tmp2)
Vectorizing loops in NumPy