# Is there a built in function to obtain the back diagonal of a matrix?

Given the following matrix:

m = Array[Subscript[a, #, #2] &, {4, 4}] how can I find the skew diagonal or anti-diagonal or back diagonal of the matrix (shown in red) • What is a "back diagonal"? Do you mean the "skew diagonal" or "anti diagonal"?
– rm -rf
Apr 13 '13 at 19:35
• You can try to apply Reverse to the matrix before Diagonal. The elements will be in reverse order so you might want to apply Reverse again to the result... Apr 13 '13 at 19:38
• Consider MapThread[Part, {Array[C, {5, 5}], -Range}]. Apr 13 '13 at 19:54

More options:

a = Range@12 ~Partition~ 4;

a // MatrixForm


$\left( \begin{array}{cccc} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \end{array} \right)$

Diagonal[Reverse @ a]

{9, 6, 3}

Diagonal[a ~Reverse~ 2, 1]

{3, 6, 9}

Diagonal[a ~Reverse~ 2]

{4, 7, 10}

Diagonal[Reverse @ a, 1]

{10, 7, 4}

Diagonal[Reverse /@ Array[f, {4, 4}]]


{f[1, 4], f[2, 3], f[3, 2], f[4, 1]}

• ...and if you want the off-antidiagonals, just use the second argument of Diagonal[]. Apr 14 '13 at 1:39

I believe you can take diagonal off a rectangular matrix too. "Back 'diagonal'".

SeedRandom;
m = RandomInteger[6, {3, 4}]
(* {{6, 4, 2, 4}, {0, 1, 6, 0}, {0, 2, 0, 6}} *)

Table[m[[i, -i]], {i, Min@Dimensions@m}]
(* {4, 6, 2} *)

• This is two orders of magnitude faster than what I proposed. Were I to answer this question today I would use this method. A very belated +1. Aug 1 '18 at 10:18

Here's a flexible version:

antidiag[m_] := Diagonal[m[[-1 ;; 1 ;; -1, 1 ;; -1 ;; 1]]]
antidiag[m_, offset_] :=
Diagonal[m[[offset ;; -1, offset ;; -1]][[-1 ;; 1 ;; -1,
1 ;; -1 ;; 1]]]


with no second argument, it gives what you want.

MatrixForm[m = Array[Subscript[a, #1, #2] &, {5, 5}]]
antidiag[m]
antidiag[m, 2] • This is probably the "correct" way to approach it, though perhaps less transparent than Reverse. Apr 13 '13 at 23:01
• @Mr.Wizard I was not aware that you were an advocate of "transparency" :) thanks.
– acl
Apr 13 '13 at 23:04
• acl: transparent~ less~ than Apr 14 '13 at 1:12
• @acl Touché! (Most of my coding is quite transparent... to myself.) Apr 14 '13 at 3:28

If by "back diagonal", you mean the diagonal from the NE corner to the SW corner of the matrix, then you can obtain it the following way:

Clear@AntiDiagonal
AntiDiagonal[m_?MatrixQ] /; Equal @@ Dimensions@m :=
Composition[Reverse, Diagonal, Reverse][m]

• If by "NE corner to the SW corner", you mean the top right to the bottom left corner, then you ... ;-) Apr 13 '13 at 20:43