Dimension vs. Rank

September 9, 2022

I’ve long been confused by the two definitions of the word dimension. Sometimes we talk about a 3-dimensional array:

float a[5][6][7];

and sometimes we talk about a 3-dimensional vector:

float v[3];

I finally figured out that the word is only correctly used in the second example above. In the first example, the term should be rank, as in, “a rank-3 array”.

So rank is the number of indices that you need to get to a scalar. In the first example you need three indices to get a float:

x = a[i][j][k];

Each of these indices has a range of valid values, and this is the dimension of that index. Again with the first example, the dimension of the first index is 5, of the second is 6, and of the third is 7. This is why it’s correct to call the second example “a 3 dimensional vector”. It has rank 1 and its only index can have three values (0, 1, and 2). Vectors are always rank 1 and matrices are always rank 2.

Looks like this terminology has always been used in mathematics. I wonder why in programming we misappropriated dimension to mean rank.

(Cover image credit: Midjourney, “photorealistic large infinite matrices in space hypercube 3d multidimensional”)