In my code, I programmatically construct a Dimensions
$(3,m)$ matrix, called mtxA
. I subsequently take its Transpose
, forming an $(m,3)$ matrix, so that it can be dotted into a vector with $3$ elements.
But sometimes, $m$ is zero, which means mtxA
looks like this :
mtxA = {{},{},{}};
Dimensions[mtxA]
(* {3, 0} *)
But now, if I take its Transpose
, I get a wrong result:
Transpose[mtxA]
% // Dimensions
(* {} *)
(* {0} *)
Instead of a $(0,3)$ matrix, I have a $(0)$ vector. And so when I try to Dot
this into a 3-vector, I get a cascade of Dot::dotsh
errors because you obviously can't dot {}
into a 3-vector.
- Is this because you can't represent a $(0,3)$ matrix in Mathematica?
- Is it possible to tell
Transpose
to preserve the rank of my matrix? - How do I deal with this problem in my code without writing a bunch of
If
statements to treat the $m=0$ case separately?
Null
for your zero dimension. For examplem = {{Null}, {Null}, {Null}}
and thenTranspose@m . {{1}, {2}, {3}}
gives{{6 Null}}
which you could, withReplaceAll
, get{{Null}}
which you could in some way interpret as having dimension $0 \times 1$. Seems a bit messy though. Overall I think @user42582 has it correct in saying that it is not directly possible; until shown otherwise. $\endgroup$