Popular understanding of tensor in deep learning and creation of tensor

1. The role of tensors in deep learning

Tensors in deep learning are mainly used to describe an object with numbers. For example, to describe a color picture, we can use (length, width, color) to describe, so to describe a color picture, you need to use three-dimensional Zhang Quantity, if we want to describe a collection of color pictures, we need to use (picture number, length, width, color) to describe, so to describe a collection of color pictures, we need to use four-dimensional tensor.
Insert picture description here

2. Tensor expression in deep learning

0-dimensional tensor:[1] A
0-dimensional tensor is a scalar, which is a number if it is plain.

1-dimensional tensor:[1,2,3,4,5]
1-dimensional tensor is a vector

2-dimensional tensor:
1 2 3 4 5 3 4 5 6 4 6 7 8 9 10 \begin{matrix}1 & 2&3&4&5\\3&4&5&6 &4\\6&7&8&9&10\end{matrix}
2-dimensional tensor is a matrix

3-dimensional tensor:
Insert picture description here
A 3-dimensional tensor is a stack of multiple 2-dimensional tensors

4-dimensional tensor:
Insert picture description here
4D tensor is a stack of multiple 3D tensors

The following picture is more intuitive:
Insert picture description here

3. Use numpy to represent tensors

0-dimensional tensor:
Insert picture description here
1-dimensional tensor:
Insert picture description here
You can get the dimensions of the tensor with the following command:
Insert picture description here

2-dimensional tensor:
Insert picture description here

3-dimensional tensor:
Insert picture description here

4. View the shape of the tensor

import numpy as np

unit_num = np.array([[[1,2,3],[2,3,4]],[[1,2,3],[2,3,4]]])
print(unit_num.shape)

result:

(2, 2, 3)
Published 41 original articles · praised 13 · visits 6692

Guess you like

Origin blog.csdn.net/comli_cn/article/details/104479674