0
$\begingroup$

At the end of a huge calculation, I am expecting a 2x2 matrix, but instead I get something like this `X = {{{{x11}}, {{x12}}}, {{{x21}}, {{x22}}}}; When I check its dimension, Mathematica says [2,2,1,1].

My question: How can I convert X into a 2x2 matrix with correct dimensions?

$\endgroup$
1
  • 2
    $\begingroup$ Are you working with vectors and using {{a, b}} for a row vector instead of just using {a, b}? $\endgroup$
    – Carl Woll
    Aug 16, 2021 at 16:28

3 Answers 3

4
$\begingroup$

another option

X = {{{{x11}}, {{x12}}}, {{{x21}}, {{x22}}}};
X = ArrayFlatten[X]

enter image description here

$\endgroup$
1
$\begingroup$
X = {{{{x11}}, {{x12}}}, {{{x21}}, {{x22}}}};
Partition[Flatten[X], 2]
$\endgroup$
1
$\begingroup$
X = {{{{x11}}, {{x12}}}, {{{x21}}, {{x22}}}};
ArrayReshape[X, {2, 2}]
(* {{x11, x12}, {x21, x22}} *)
$\endgroup$

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.

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