return out

def indices_app(matrix, X, Y):
    coords_ext = np.empty((Y, X, 3))
coords_ext[..., ([1, 0])] = np.rollaxis(np.indices((Y, X)), 0, start=3)
coords_ext[..., (2)] = 1
result = np.matmul(coords_ext, matrix.T)
return result

def broadcasting_app(matrix, X, Y):
    ys = np.arange(Y)
xs = np.arange(X)
out = ys[:, (None), (None)] * matrix[:, (1)] + xs[:, (None)] * matrix[:, (0)
    ] + matrix[:, (2)]
return out
Rigid transformation - Python - speedup