Organize the information you need to understand Tensor as your own notes. At the same time, I will introduce the Tensor notation in Python.
Continuing from the previous article, this time I would like to introduce Tensor's Shape. Understanding the tensor (1): Dimension
A tensor is a container that holds numbers. It's simple.
It means Tensor, Dimension, Axis, Ranks.
A tensor is a generalized representation of the matrix.
name | tensor | Notation |
---|---|---|
Scalar | 0 Dimensional Tensor | Not Available |
Vector | 1 Dimensional Tensor | (k) |
Matrix | 2 Dimensional Tensor | (j,k) |
.. | 3 Dimensional tensor | (i,j,l) |
A tensor shape is information that indicates ** how many elements each Dimension (= axis) is composed of **. From experience, it is easy to understand Shape above 2D tensor (Matrix), but it is necessary to understand Shape of 0D tensor (Scalar) and 1D tensor (Vector) after seeing an example.
You can check the shape of Tensor with the shape command of Python.
4.1 Scalar : 0D Tensor
Scalar has empty shape.
Take, for example, the number 12. The number 12 is Scalar because there is only one number. Scalar is a 0D Tensor. That is, the Dimension of the Tensor is zero. There is no Dimension. Since the information on the number of elements of the missing Dimension is Shape, the Shape of Scalar can only be written in ** () **. This is called Scalar has empty shape. In English. It's a bit unreasonable, but please bear with Vector.
Let's output the Scalar Shape with the code below.
4.2 Vector : 1D Tensor
1D tensor has a shape with a single element, such as (4, ).
The following is an example of a Vector.
\begin{bmatrix}
12 & 3 & 6 & 14
\end{bmatrix}
Vector is a 1D tensor. Since there is only one Dimension, one number represents the Shape. And the number of Elements of this Vector is 4. Therefore, the Shape of this Vector is written as ** (4,) **. This may not come to mind, but you have to remember it.
Let's output the Shape of Vector with the following code.
4.3 Matrix : 2D Tensor
2D tensor has a shape such as (3,4). it is familiar with matrix representation.
The following is an example of Matrix.
\begin{bmatrix}
1 & 3 & 5 & 7 \\
2 & 4 & 6 & 8 \\
3 & 6 & 9 & 12
\end{bmatrix}
The Shape of this Matrix is ** (3,4) **. It is the same as the notation of a matrix in mathematics so far. Actually, Matrix is a 2D Tensor, so it is written with two numbers. Each number will contain the number of Elements for each Dimension.
Let's output the Matrix Shape with the code below.
4.4 .. :3D Tensor
3D tensor has a shape (*3*,3,4).
The following is an example of a 3D tensor. When it comes to 3D Tensor, it becomes difficult to express it as a mathematical formula, so please use code notation. Imagine that there are three matrices (3,4) in a row. In this case, the Shape of this tensor is (3, 3, 4).
[[[1, 3, 5, 7],[2, 4, 6, 8],[3 ,6, 9,12]], [[1, 3, 5, 7],[2, 4, 6, 8],[3 ,6, 9,12]], [[1, 3, 5, 7],[2, 4, 6, 8],[3 ,6, 9,12]]]
I organized the meaning of Shape of Tensor and the expression in Python. Next time, I will introduce an example of Tensor.
name | tensor | Expression | Shape |
---|---|---|---|
Scalar | 0D Tensor | Not Available | () |
Vector | 1D Tensor | (k) | (k,) |
Matrix | 2D Tensor | (j,k) | (j,k) |
.. | 3D tensor | (i,j,l) | (i,j,l) |
Recommended Posts