3
$\begingroup$

I have a 32 x 32 matrix U. I want to create a new matrix (the "partial transpose"), leaving in place the two 16 x 16 diagonal blocks of U, and transposing in place the two 16 x 16 off-diagonal blocks. How might/should I do this?

Also, I create U itself from a 4 x 4 array of 8 x 8 matrices, call them V[[i,j]], by using

ArrayReshape[{{V[[1,1]],V[[1,2]],V[[1,3]],V[[1,4]]},
              {V[[2,1]],V[[2,2]],V[[2,3]],V[[2,4]]},
              {V[[3,1]],V[[3,2]],V[[3,3]],V[[3,4]]},
              {V[[4,1]],V[[4,2]],V[[4,3]],V[[4,4]]}},{32,32}]

This I take it should work in the "natural" fashion. Could the same be accomplished with the Flatten command? Would some other code be appropriate?

$\endgroup$
  • $\begingroup$ And V is defined as...? $\endgroup$ – Feyre Nov 1 '16 at 22:39
  • $\begingroup$ Feyre asked how V is defined. While I think the question is essentially independent of the precise nature of V, I will say that the 8 x 8 matrices are real representations of octonions (eq. (1) in actaphys.uj.edu.pl/fulltext?series=Reg&vol=47&page=1113) the values of which I set to normal distribution (Ginibre ensemble) values. $\endgroup$ – Paul B. Slater Nov 2 '16 at 2:25
4
$\begingroup$

Consider

n = 8;
(U = RandomInteger[{0, 9}, {n, n}]) // MatrixForm

enter image description here

(T = Partition[U, {n/2, n/2}]) // MatrixForm

enter image description here

(t = Transpose @ T) // MatrixForm

enter image description here

ArrayFlatten @ t // MatrixForm

enter image description here

In the above I interpreted "transposing in place the two 16 x 16 off-diagonal blocks" as interchanging the position of the two off-diagonal blocks.


The OP clarified in a comment that he wants to transpose the two blocks themselves, so for this matter:

t = T;

t[[1, 2]] = Transpose @ t[[1, 2]];
t[[2, 1]] = Transpose @ t[[2, 1]];

ArrayFlatten @ t // MatrixForm

enter image description here

or compactly, as C.E. proposed:

t = ArrayFlatten @ MapAt[Transpose, T, {{1,2},{2,1}}]
$\endgroup$
  • 3
    $\begingroup$ +1, this is a nicely written answer. If "transposing in place the two 16 x 16 off-diagonal blocks" means transposing each block individually, I'd recommend ArrayFlatten@MapAt[Transpose, T, {{1,2},{2,1}}]. $\endgroup$ – C. E. Nov 1 '16 at 22:57
  • 1
    $\begingroup$ What the code of corey979 accomplishes, I think, is to interchange the two off-diagonal blocks, while what I intended was not to interchange them, but just to transpose them in place (emphasis added). The two approaches would be equivalent in terms of further analyses if they were to yield the same set of eigenvalues. (The 32 x 32 matrix is symmetric, by prior construction--which I had not mentioned--so the eigenvalues would then be real.) The answer of C. E. appears to accomplish what I intended--so I will mark it as an answer, upon a little further reflection/checking. Thanks to all! $\endgroup$ – Paul B. Slater Nov 2 '16 at 0:07
  • $\begingroup$ Well, while the comment of C. E. does answer my (first/main) question, it is provided as a comment not an answer--so I can not directly vote for it. $\endgroup$ – Paul B. Slater Nov 2 '16 at 2:35
  • 1
    $\begingroup$ @PaulB.Slater Please see the edited answer. $\endgroup$ – corey979 Nov 2 '16 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.