Reshaping
Some operations, such as addition, can only be applied to tensors if they meet certain conditions. Reshaping is one method for modifying the shape of tensors so that such operations can be performed. Reshaping takes the elements of a tensor and rearranges them into a tensor of a different size. A tensor of any size can be reshaped so long as the number of total elements remains the same.
For example, a (4x3)
matrix can be reshaped into a (6x2)
matrix since they both have a total of 12
elements. The rank, or number, of dimensions, can also be changed in the reshaping process. For instance, a (4x3)
matrix that has a rank equal to 2
can be reshaped into a (3x2x2)
tensor that has a rank equal to 3
. The (4x3)
matrix can also be reshaped into a (12x1)
vector in which the rank has changed from 2
to 1
.
Figure 1.13 illustrates tensor reshaping. On the left is a tensor with shape (3x2)
, which can be reshaped to a tensor of shape equal to either (2x3)
, (6)
, or (6x1)
. Here...