You can do this using an intersection of horizontal and vertical patterns:
import numpy as np
N = 5
H = abs(np.arange(1-N,N+1,2))//2
V = H[0] - H[:,None]
diamond = (H==V)*1
print(diamond)
[[0 0 1 0 0]
[0 1 0 1 0]
[1 0 0 0 1]
[0 1 0 1 0]
[0 0 1 0 0]]
Visually, this corresponds to intersecting number equalities between rows and columns:
for N=7:
[3, 2, 1, 0, 1, 2, 3]
0 . . . x . . .
1 . . x . x . .
2 . x . . . x .
3 x . . . . . x
2 . x . . . x .
1 . . x . x . .
0 . . . x . . .
for N=8:
[3, 2, 1, 0, 0, 1, 2, 3]
0 . . . x x . . .
1 . . x . . x . .
2 . x . . . . x .
3 x . . . . . . x
3 x . . . . . . x
2 . x . . . . x .
1 . . x . . x . .
0 . . . x x . . .
If you want the diamond to be filled, use diamond = (H<=V)*1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…