According to the documentation, Transpose with a second argument {1,1} on a square matrix returns the diagonal of the matrix.

m = ArrayReshape[Range[25], {5, 5}];
Transpose[m, {1, 1}] == Diagonal[m]
(* True *)

Is it an arbitrary convention for the Transpose function, or does it correspond to some mathematical reality? It does not seem like an obvious consequence of the definition of transposition to me.

  • 4
    $\begingroup$ The documentation OP is referring to mentions this: Transpose allows the $n_i$ to be repeated, computing diagonals of the subarrays determined by the repeated levels. The result is therefore an array of smaller depth. $\endgroup$
    – flinty
    Feb 7, 2022 at 11:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.