python-3.xvectordimensions

Dimension of a vector composed of n-dimensional base vectors


I have an issue understanding the dimension of vectors. A vector v composed of m base vectors has a dimension m. However, if those m vectors are n-dimensional, then the dimension of v is m or m*n? For example, when I run the command v.shape, I get (28, 28, 128). Then this means that the dimension of v is 28x28x128? Or I just consider the base vectors, that is 28?


Solution

  • As mentioned by @Brian61354270 in a comment to the OP, there seems to be a misunderstanding - conflating the meanings of dimension in mathematics and coding in Python. In mathematics, the dimension of a vector space is the number of coordinates needed to specify any vector within that space. If you have a vector,v, composed of m base vectors (a set of vectors that, in a linear combination, can represent every vector in a given vector space - these basis vectors span the vector space) in an n-dimensional space, v is m-dimensional, where each base vector itself is n-dimensional.

    In Python, and specifically with the NumPy library, the term "dimension" usually refers to the shape or structure of arrays (or tensors). For example, an array with shape (28, 28, 128) is a 3-dimensional array with sizes 28, 28, and 128 along its three axes, respectively. This does not directly correspond to the mathematical definition of a vector's dimension but rather indicates the structure and organisation of data in memory. Many other languages (eg R, Julia and Matlab) as well as other Python libraries (eg TensorFlow and PyTorch) use this approach, and from my experience, it is fairly ubiquitous. The only areas I have seen the mathematical approach used is with numerical computing libraries for Haskell, though I'm sure there are others.