# A simple way to get dimensions of a matrix "by eye"

I can’t seem to remember how the notation specifies rows or columns.

I found though, a heuristic for it that works well, and it is simple.

Say we have the matrices:

``````X = [[1,2],[3,4],[5,6]]
Y = [[1],[3],[5]]
Z = [ [[4,2], [3,1], [4,45]], [[4,2], [3,1], [4,45]] ]
``````

According to this method the dimensions `[ ]` are:

``````[ X ] = 3 x 2
[ Y ] = 3 x 1
[ Z ] = 2 x 3 x 2
``````

The steps are:

• Count the number of elements (L_1) at the lowest level
• Then the dimension is the number L_1

This step is repeated for each dimension, and you write it backwards, i.e
D = L_n, \dots, L_3, L_2, L_1

So for Z, the lowest level elements are arrays `[a,b]` (that is the last number you specify).

• Also the number of commas + 1 will yield the right value.

The next level has 2 `,` so D is 3. We have 3 x 2 so far.

To my eyes it is easier to see the inner dimension first.

You can check it in python as:

``````>>> import numpy as np
>>> np.array(Z)
array([[[ 4,  2],
[ 3,  1],
[ 4, 45]],

[[ 4,  2],
[ 3,  1],
[ 4, 45]]])
>>> Z = np.array(Z)
>>> Z.shape
(2, 3, 2)
``````

Sounds reasonable.

I may count the number of elements, not “commas”, simply because “comma” is too small…
And, also use this to double check the number of array dimension. (= numpy ndim)

But, to be honest, as the number of dimensions is too high in Tensorflow, I almost give up to see in detail in my eyes, and totally rely on the computer with applying shape, slice, ndim, etc.

Thanks for your reply. Yes, absolutely, it is actually better to trust the program after you get the idea…