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.
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:
2-dimensional tensor is a matrix
3-dimensional tensor:
A 3-dimensional tensor is a stack of multiple 2-dimensional tensors
4-dimensional tensor:
4D tensor is a stack of multiple 3D tensors
The following picture is more intuitive:
3. Use numpy to represent tensors
0-dimensional tensor:
1-dimensional tensor:
You can get the dimensions of the tensor with the following command:
2-dimensional tensor:
3-dimensional tensor:
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)