You can iterate through the array and consider how far away from the center each element is, taking the maximum over both dimensions. For example, if the element is within one row and one column of the center, then there should be a 1 in that position, but if it's within one row and two columns of the center, then there should be a 2 in that position, and so on. Here's an example:
import numpy as np
def border(x):
arr = np.zeros((x, x))
center = x // 2
for i in range(x):
for j in range(x):
arr[i, j] = max(abs(center - i), abs(center - j))
return arr
Example output:
>>> border(5)
array([[2., 2., 2., 2., 2.],
[2., 1., 1., 1., 2.],
[2., 1., 0., 1., 2.],
[2., 1., 1., 1., 2.],
[2., 2., 2., 2., 2.]])
>>> border(7)
array([[3., 3., 3., 3., 3., 3., 3.],
[3., 2., 2., 2., 2., 2., 3.],
[3., 2., 1., 1., 1., 2., 3.],
[3., 2., 1., 0., 1., 2., 3.],
[3., 2., 1., 1., 1., 2., 3.],
[3., 2., 2., 2., 2., 2., 3.],
[3., 3., 3., 3., 3., 3., 3.]])