x_lattice = lattice_vectors[0][0] * x_sq + lattice_vectors[1][0] * y_sq
y_lattice = lattice_vectors[0][1] * x_sq + lattice_vectors[1][1] * y_sq
mask = (x_lattice < image_shape[0] / 2.0) & (x_lattice > -image_shape[0] / 2.0)
mask = mask & ((y_lattice < image_shape[1] / 2.0) & (y_lattice > -
    image_shape[1] / 2.0))
x_lattice = x_lattice[mask]
y_lattice = y_lattice[mask]
x_lattice += center_pix[0]
y_lattice += center_pix[1]
out = np.empty((len(x_lattice), 2), dtype=float)
out[:, (0)] = y_lattice
out[:, (1)] = x_lattice
return out
Efficiently generate a lattice of points in python