Skip to main content
4 of 6
added 65 characters in body
kglr
  • 400.5k
  • 18
  • 488
  • 929
array = ConstantArray[1, {5, 5}];
Fold[ArrayPad, array, {-1, 1}] // MatrixForm // TeXForm 

$\left( \begin{array}{ccccc} 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 1 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ \end{array} \right)$

Also

ArrayPad[ArrayPad[array, -1], 1] // MatrixForm // TeXForm  
ArrayPad[array[[2 ;; -2, 2 ;; -2]], 1] // MatrixForm // TeXForm
MapAt[0 &, array, {{All, {1, -1}}, {{1, -1}, All}}] //  MatrixForm // TeXForm 
ReplacePart[array, {1 | Dimensions[array][[1]], _} | {_, 1 | Dimensions[array][[2]]} :> 0]
  // MatrixForm // TeXForm

all give

$\left( \begin{array}{ccccc} 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 1 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ \end{array} \right)$

kglr
  • 400.5k
  • 18
  • 488
  • 929