I have this matrix:
mat = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16,
17, 18, 19, 20}, {21, 22, 23, 24, 25}};
and here are its second row and second column:
{mat[[2]], mat[[All, 2]]}
(* {{6, 7, 8, 9, 10}, {2, 7, 12, 17, 22}} *)
When I tried to change its second column to all zeros, this method works:
mat = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16,
17, 18, 19, 20}, {21, 22, 23, 24, 25}};
mat[[All, 2]] = 0;
mat // MatrixForm
But using the method to change the second row, the entire row become a big zero:
mat = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16,
17, 18, 19, 20}, {21, 22, 23, 24, 25}};
mat[[2]] = 0;
mat // MatrixForm
My question is:
1) Why would the replacement of a row versus a column in a matrix different?
2) Why would setting the list of all column elements to zero automatically set each of them to zero? Setting a list to a single number doesn't seem to work in isolation:
{a, b, c} = 0
mat
to be0
? This is the logical way to do that. $\endgroup$mat = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25}}; {mat[[1, 2]], mat[[2, 2]], mat[[3, 2]], mat[[4, 2]], mat[[5, 2]]} = 0; mat
. $\endgroup$