import numpy as np n = 8 matrix = np.fromfunction(lambda i, j:(i+j) % 2, (n, n) dtype=int) print(matrix)