2

I am puzzled with the following. How can I create a, e.g., 10x10 array A[i,j] where the border is filled with 1's and the rest of the elements are 0?

Thanks

Dimitris
  • 4,794
  • 22
  • 50

1 Answers1

6

Kuba suggested

ArrayPad[ConstantArray[0, {8, 8}], 1, 1]

Similarly, you can do this:

CenterArray[ConstantArray[0, {8, 8}], {10, 10}, 1]

J.M. proposed the following:

1 - BoxMatrix[3, {10, 10}]

One may also use

SparseArray[{{1, _} -> 1, {_, 1} -> 1, {-1, _} -> 1, {_, -1} -> 1}, {10, 10}]

Normal can be used if an explicit (rather than a sparse) array is desired.

C. E.
  • 70,533
  • 6
  • 140
  • 264