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


But if I consider instead,

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

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


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.

  • $\begingroup$ Dimensions does not only work with lists. Take a look at FullForm of expressions you use in Dimensions. $\endgroup$
    – Kuba
    Apr 4 '17 at 9:27
  • $\begingroup$ @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. $\endgroup$
    – user32416
    Apr 4 '17 at 9:29
  • 1
    $\begingroup$ So you would like Dimensions which only respects List head? Good question. $\endgroup$
    – Kuba
    Apr 4 '17 at 9:39
  • $\begingroup$ You might consider doing a preliminary test with ArrayQ[]. $\endgroup$
    – J. M.'s torpor
    Apr 4 '17 at 9:43
  • $\begingroup$ Perhaps TensorDimensions would be better used in this context. $\endgroup$ 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]]]

So I believe, this could be achieved like so:

listDimensions[arg_] := Rest@Dimensions[{arg}]
  • $\begingroup$ Missed this for some reason. I have given you my last upvote for today. $\endgroup$
    – J. M.'s torpor
    Nov 15 '17 at 10:46

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.