# Dimensions --- counter-intuitive?

Perhaps I'm misunderstanding the meaning of Dimensions in Mathematica, but the following two examples seem very counter-intuitive to me.

If we define

a = {1,2,3}
b = {4,5,6}


then we compute the dimension of its dot product Dimension[ a . b ], I get the "empty" result

{}


aa = {a1, a2, a3}
bb = {b1, b2, b3}


and compute the same thing Dimension[ aa . bb ], I get the result

{3}


Is this behavior to be expected? I understand that the first case has known constants, and while the second case has unknown constants. But regardless, both are simply scalars, and I would expect Dimensions would return the same answer in both cases.

• Dimensions does not only work with lists. Take a look at FullForm of expressions you use in Dimensions.
– Kuba
Apr 4 '17 at 9:27
• @Kuba I see. Once I look at the FullForm, I see that the first and second case yield wildly different forms. But is there a function in Mathematica where if I literally want to just "count dimensions", they would both yield the same result? For instance, as far as I can tell, in Mathematica, an $n \times m$ matrix of known constants and unknown constants yield the same answer in Dimensions. Apr 4 '17 at 9:29
• So you would like Dimensions which only respects List head? Good question.
– Kuba
Apr 4 '17 at 9:39
• You might consider doing a preliminary test with ArrayQ[]. Apr 4 '17 at 9:43
• Perhaps TensorDimensions would be better used in this context. Aug 9 at 9:44

So you would like Dimensions which only respects List head? Good question. -- Kuba

From the documentation:

The "array" is considered full only when it has the same head as at the top:

Dimensions[f[g[x, y], g[a, b], g[s, t]]]
{3}


So I believe, this could be achieved like so:

listDimensions[arg_] := Rest@Dimensions[{arg}]
listDimensions[a.b]
listDimensions[aa.bb]

{}
{}

• Missed this for some reason. I have given you my last upvote for today. Nov 15 '17 at 10:46