MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Why does Transpose[m, {1, 1}] give the diagonal of m?

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1859] Why does Transpose[m, {1, 1}] give the diagonal of m?
  • From: drc at gate.net (David Cabana)
  • Date: Wed, 9 Aug 1995 22:37:45 -0400

In a recent article in the thread Re: [mg1741] RealDigits, Roman Maeder explains
one way to test whether a matrix is diagonal:

>even faster and certainly simpler:
>dQ[m_?MatrixQ] /; SameQ @@ Dimensions[m] :=
>        m == DiagonalMatrix[Transpose[m, {1, 1}]]
>(note: Transpose[m, {1, 1}] returns the list of diagonal elements.)

An elegant test.  My question: why does Transpose[m, {1, 1}] return 
the list of diagonal elements?  Looking under Transpose in Wolfram's 
Mathematica Reference Guide (an appendix to Mathematica, 2nd ed.), 
I find:

>Transpose[list, {n1,n2, ...}] transposes list so that the kth level
>in list is the nkth level in the result.

I expected Depth[Transpose[list, {n1,n2, ...}]] to be the same as 
Depth[list].  I expected Transpose to swap levels; I did not
expect it to throw any away.  Evidently I am laboring under some
misconception.  Can someone explain what is going on?

-- 
David Cabana   drc at gate.net


  • Prev by Date: Re: Math co-processor
  • Next by Date: Fuzzy in mathematica
  • Previous by thread: Axis direction
  • Next by thread: Re: Why does Transpose[m, {1, 1}] give the diagonal of m?