# Looking for a simple way to manipulate one column of a matrix

Given

{{a, b}, {c, d}}


I want to get

{{c, b}, {a, d}}


with one simple expression. Is this possible?

• With m = {{a, b}, {c, d}}, use m[[;; , 1]] = m[[Dimensions[m][] ;; 1 ;; -1, 1]]? – egwene sedai May 10 '19 at 14:35

You can use SubsetMap for this:

l = {{a, b}, {c, d}}

SubsetMap[Reverse, l, {All, 1}]


{{c, b}, {a, d}}

That is, Reverse and replace the list of elements comprised of the 1nth element of All rows of l.

There are bound to be many other solutions.

I suggest making use of function argument destructuring. The required munger can be written directly from the problem statement. No need to dig out arcane knowledge of list manipulation.

mung[{{a_, b_}, {c_, d_}}] := {{c, b}, {a, d}}
m = {{a, b}, {c, d}}; mung[m]


{{c, b}, {a, d}}

Diagonal /@ {Reverse[m], m}


{{c, b}, {a, d}}

Transpose @ MapAt[Reverse, Transpose[m], {1}]


{{c, b}, {a, d}}

Your question is tagged both "list-manipulation" and "matrices". Other answers have given answers treating this as a nested list, but if you want to do it with matrix operations, the two columns of the resulting matrix are {{0, 1}, {1, 0}}.{{a, b}, {c, d}}.{{1},{0}} and {{a, b}, {c, d}}.{{0},{1}}, so you can them combine those two column vectors into a matrix to get the answer.