# What is the meaning of 2D vectors?

I keep hearing people say something like:

lets say you have a 1 dimensional vector of a person that just has his age. Then you add another dimension which is his height, so you have a 2 dimensional vector

But I also heard things like

A 2d vector is a rank 2 tensor

Can someone clarify which is the correct one?

Is it

[1, 1]

or

[[1,1],
[1,1]]


"Tensor" is a very general term, meaning N-dimensional array. A tensor can be 0-dimensional (a scalar), 1-dimensional (a vector), 2-dimensional (a matrix), and so on... Tensor is a very encompassing term, meaning all of the things listed above. Sometimes, people use "tensor" to refer to high dimensional objects, as explained here:

While, technically, all of the above constructs are valid tensors, colloquially when we speak of tensors we are generally speaking of the generalization of the concept of a matrix to N ≥ 3 dimensions. We would, then, normally refer only to tensors of 3 dimensions or more as tensors, in order to avoid confusion [...]

But please keep in mind that this is just a practice, and N-dimensional array is technically a tensor.

Coming to your question, if a tensor is more like:

[1, 1]


or

[[1,1],
[1,1]]


First, they look like Python list and list of lists, respectively. Python lists are not mathematical objects, strictly speaking. Provided you imported numpy, it would be more correct to describe them as:

numpy.array([ 1, 1 ])


and

numpy.array([[ 1, 1 ],
[ 1, 1 ]])


Now these objects have the mathematical properties of vectors-matrices-tensors. I think they could both be thought as tensors of different kinds and ranks. The first is of rank 1, the other of rank 2.

Other useful resources on tensors are this question, and this explanation.

• Thanks for the effort and reply. It seems maybe I wasn't clear in the question. As I do understand about what tensors ranks mean, I wasn't sure if a 2d vector meant a 2x2 matrix or a vector with 2 elements. Commented Jan 8, 2020 at 8:56
• 2D vector = 2D matrix = rank 2 tensor. 2x2 is a size, not a rank. 2-dimensional and 2x2 are different concepts. Sorry for not being clear about this. Commented Jan 8, 2020 at 8:59
• Ah sorry! I knew that! 2x2 or 2x3 are still rank 2 tensors. Okay, so when someone says to me, i have 3 dimensions in my feature vector because we have age, height, and name. Is he wrong for saying that? Commented Jan 8, 2020 at 9:05
• A vector with three variables: age, height, name is a 3D vector, i.e. a tensor of rank 3. Or a three-dimensional matrix, they are equivalent expressions. Commented Jan 8, 2020 at 10:38
• And what is the shape of that 3d vector? If it was 3x1x1 or 1x1x3 that will make sense, but usually we store it as shape of 3 Commented Jan 8, 2020 at 17:41

import torch
x = torch.tensor([1, 1])
y = torch.tensor([[ 1, 1 ], [ 1, 1 ]])
print("x dimension: {}".format(x.dim()))
print("y dimension: {}".format(y.dim()))


gives:

x dimension: 1
y dimension: 2


So your first vector/tensor with age and height of one single(!) person has only one dimension and your second vector/tensor has two dimensions.

• So this is the way I thought too, however please read the latest comment on that answer Commented Jan 8, 2020 at 17:42

In Python, you can think of vector dimensionality as list-of-lists-of-lists-of....

So,

1. list = 1D
2. list-of-lists = 2D
3. list-of-lists-of-list = 3D
4. and so on...
[1,1] # 1D

[[1,1],
[1,1]] # 2D

[[[1,1],
[1,1]],
[[1,1],
[1,1]]] # 3D


Then you mentioned:

Then you add another dimension which is his height, so you have a 2 dimensional vector.

I think this can be interpreted in two ways:

[<age>] # 1D of size 1x1

# You can add height and make it 2D
[[<age>],
[<height>]] # 2D of size 2x1

# or, add height and keep it 1D
[<age>, <height>] # 1D of size 1x2

• Ah yes, this is the way I thought as well. However if you wanted to say we have four dimensions since we have age height weight and id, then itll literally be a 1x1x1x4 or 4x1x1x1 tensor which seems unneccesary. Commented Jan 8, 2020 at 17:45
• I guess then you can either have a 4x1 or a 1x4. You don't need to keep nesting like you did. More generally you could have 4xn or nx4 where n=number of samples. Then you are always at 2D. Commented Jan 9, 2020 at 7:33