import numpy as np array = np.ones((5, 5)) x, y = np.indices((5, 5)) array = np.where((x == 0) | (x == 4) | (y == 0) | (y == 4), 1, 0) print(array)