I have f.e. the following square matrix:
x = {{2, 5, 5, 11, 11, 23, 37, 41, 43, 47},
{2, 5, 11, 17, 19, 23, 41, 41, 43, 67},
{2, 7, 11, 19, 19, 41, 41, 43, 47, 73},
{3, 11, 17, 19, 23, 41, 43, 53, 67, 79},
{3, 11, 19, 19, 31, 43, 47, 59, 67, 83},
{3, 17, 19, 29, 37, 43, 53, 59, 73, 83},
{5, 17, 29, 31, 37, 47, 53, 71, 73, 83},
{7, 19, 29, 31, 37, 53, 59, 73, 73, 89},
{11, 23, 31, 41, 43, 53, 61, 73, 79, 97},
{29, 29, 37, 41, 53, 67, 71, 79, 79, 97}};
I want to keep the first and last row / column and replace all other numbers with 0
. I have written:
n = Length@First@x;
Table[x[[i, j]] = 0, {i, 2, n - 1}, {j, 2, n - 1}];
x // MatrixForm
Before that I tried to find a more functional solution (f.e. with replacement patterns) but gave up after some unsuccesful attempts. Thanks for showing me some alternatives.