# What's the difference between a 1d tensor and a 2d tensor with 1 dimension?

I'm doing a TensorFlow tutorial, where they convert an array of the numbers [1,2,3] to a tensor like this:

const xs = tf.tensor2d([1, 2, 3], [3, 1])


The shape is [3,1] because there is one row with 3 numbers. My question is, why would they use a 2D tensor, isn't this just exactly the same as:

const xs = tf.tensor1d([1, 2, 3])

• This seems to be just a programming question/issue. Am I right? If yes, then you should ask this question on Stack Overflow, as programming questions are generally off-topic here. Please, if you have some time, take a look at our on-topic page, where we describe what kind of question you can ask here. – nbro Apr 16 at 9:53
• I posted it here because it's not really about code but about the difference in 1d or 2d tensors. Unless that is also considered code? – Kokodoko Apr 16 at 10:17
• To give a proper answer, I think we will need more context, i.e. please provide the link to the tutorial where the first version of the code is used. – nbro Apr 16 at 10:53

The required shape of the tensor $$T$$ depends on the shape of other tensors that are involved in the same operations of that same tensor $$T$$ and the required/desired shape of the resulting tensor, in the same way that the number of columns of the matrix $$M \in \mathbb{R}^{n \times m}$$ needs to match the number of rows of the matrix $$M' \in \mathbb{R}^{n' \times m'}$$ when you perform the matrix multiplication $$M M'$$, i.e. in order for $$M M'$$ to be well-defined, $$m = n'$$.