Answers.Body: <p>The required shape of the tensor <span class="math-container">$T$</span> depends on the shape of other tensors that are involved in the same operations of that same tensor <span class="math-container">$T$</span> and the required/desired shape of the resulting tensor, in the same way that <a href="https://en.wikipedia.org/wiki/Matrix_multiplication" rel="nofollow noreferrer">the number of columns of the matrix <span class="math-container">$M \in \mathbb{R}^{n \times m}$</span> needs to match the number of rows of the matrix <span class="math-container">$M' \in \mathbb{R}^{n' \times m'}$</span> when you perform the matrix multiplication <span class="math-container">$M M'$</span>, i.e. in order for <span class="math-container">$M M'$</span> to be well-defined, <span class="math-container">$m = n'$</span></a>.</p>
  <p>So, in your case, although the tensors contain the same elements, it might not be possible to use both in the same operations. Without more context/details, I cannot specifically answer why the first tensor was used in the tutorial you're mentioning.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-16T13:25:20.160Z
Answers.LastActivityDate: 2021-04-16T13:25:20.160Z
Answers.UserDisplayName: nbro
Body: <p>I'm doing a TensorFlow tutorial, where they convert an array of the numbers <code>[1,2,3]</code> to a tensor like this:</p>
  <pre><code>const xs = tf.tensor2d([1, 2, 3], [3, 1])
  </code></pre>
  <p>The shape is <code>[3,1]</code> 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:</p>
  <pre><code>const xs = tf.tensor1d([1, 2, 3])
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-16T09:53:49.690Z
Comments.Text: 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](https://ai.stackexchange.com/help/on-topic), where we describe what kind of question you can ask here.
Comments.UserDisplayName: nbro
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-16T10:17:26.433Z
Comments.Text: 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?
Comments.UserDisplayName: Kokodoko
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-16T10:53:31.787Z
Comments.Text: 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.
Comments.UserDisplayName: nbro
Tags: <machine-learning><tensorflow><math><linear-algebra>
Title: What's the difference between a 1d tensor and a 2d tensor with 1 dimension?
UserDisplayName: Kokodoko
ThreadText: # What's the difference between a 1d tensor and a 2d tensor with 1 dimension?
  
  (Asked by: username_0 on 2021-04-16)
  
  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])
  
  ```
  
  **Tags:** machine-learning, tensorflow, math, linear-algebra
  
  > **Comments:**
  > **username_1**: 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](https://ai.stackexchange.com/help/on-topic), where we describe what kind of question you can ask here.  
  > **username_0**: 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?  
  > **username_1**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-04-16. Score: 1 | Accepted answer
  
  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'$](https://en.wikipedia.org/wiki/Matrix_multiplication).
  
  So, in your case, although the tensors contain the same elements, it might not be possible to use both in the same operations. Without more context/details, I cannot specifically answer why the first tensor was used in the tutorial you're mentioning.
  
  
  ---
  
  