I want to fill the first and the last row and the first and the last column of a grid with 4.
Input:
grid = np.zeros((5, 5))
[[ 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 0. ]]
output:
[[ 4. 4. 4. 4. 4. ]
[ 4. 0. 0. 0. 4. ]
[ 4. 0. 0. 0. 4. ]
[ 4. 0. 0. 0. 4. ]
[ 4. 4. 4. 4. 4. ]]
I tried to do this with a for loop but is there a better option than that?