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
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
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.
ConstantArray+ArrayPad– Kuba Apr 08 '17 at 11:17BoxMatrix[]. – J. M.'s missing motivation Apr 08 '17 at 11:19BoxMatrixcreates a matrix that is (2r+1)x(2r+1). There is no way to selectrsuch that the dimension of the matrix is 10x10. – C. E. Apr 08 '17 at 15:281 - BoxMatrix[3, {10, 10}]works for me. – J. M.'s missing motivation Apr 08 '17 at 15:31