# How do I get the permutation matrix of an element in the symmetric group?

I have a permutation in $$S_4$$, Cycles[{2, 4}]. I want to produce the permutation matrix of this permutation. In other words, I want Mathematica to return the list {{1, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 0}}.

• This seem the Identy Matrix with the rows 2 and 4 interchanged. Table[IdentityMatrix[4][[i]],{i,PermutationList[Cycles[{{2, 4}}], 4]}] Apr 13, 2020 at 13:26

n = 4
SparseArray[
Transpose[{Range[n], PermutationList[Cycles[{{2, 4}}], n]}] -> 1,
{n, n}
]

• You don't even need to define n if you do SparseArray@MapIndexed[{#2[[1]], #1} -> 1 &, PermutationList[Cycles[{{2, 4}}]]]. Apr 13, 2020 at 12:22
• I know. Btw., calling SparseArray  and PermutationList without a second argument is asking for trouble. And Map and friends are slow. ;) Apr 13, 2020 at 12:25

IdentityMatrix[4][[#]]&/@PermutationList[Cycles[{{2, 4}}], 4]

• Thank you. This is very helpful. Apr 13, 2020 at 13:57
• IdentityMatrix[4][[PermutationList[Cycles[{{2, 4}}], 4]]] is a bit simpler. Apr 13, 2020 at 13:58
• also: Permute[IdentityMatrix[4], Cycles[{{2, 4}}]] (+1)
– kglr
Apr 13, 2020 at 16:43

Starting in version 13.1, one can just evaluate

PermutationMatrix[Cycles[{{2, 4}}]] // Normal
{{1, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 0}}


but it might be better to omit the Normal[] and keep the matrix in its structured form, since internal operations like Dot[] are optimized to work with the structured form.