Skip to main content
3 of 6
added 90 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  (* or *)
MapAt[0 &, array, {{All, {1, -1}}, {{1, -1}, All}}] //  MatrixForm // TeXForm (* or *)
ReplacePart[array, {1 | Dimensions[array][[1]], _} | {_, 1 | Dimensions[array][[2]]} :> 0]
  // 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)$

kglr
  • 400.5k
  • 18
  • 488
  • 929