Hands-On Neural Networks with Keras
上QQ阅读APP看书,第一时间看更新

Examples of tensors

The illustration we previously saw was that of a three dimensional tensor, yet tensors can appear in many forms. In the following section, we will overview some tensors of different ranks, starting with a tensor of rank zero:

  • Scalar: Values simply denote a single numeric value on its own. This can also be described as a tensor of dimension 0. An example of this is processing a single grayscale pixel of an image through a network.
  • Vector: A bunch of scalars or an array of numbers is called a vector, or a tensor of rank 1. A 1D tensor is said to have exactly one axis. An example of this is processing a single flattened image.
  • Matrix: An array of vectors is a matrix, or 2D tensor. A matrix has two axes (often referred to as rows and columns). You can visually interpret a matrix as a rectangular grid of numbers. An example of this is processing a single grayscale image.
  • Three-dimensional tensor: By packing several matrices into a new array, you get a 3D tensor, which is visually interpretable as a cube of numbers. An example of this is processing a dataset of grayscale images.
  • Four-dimensional tensor: By packing 3D tensors in an array, you can create a 4D tensor, and so on. An example of this is processing a dataset of colored images.
  • Five-dimensional tensor: These are created by packing 4D tensors in an array. An example of this is processing a dataset of videos.