Scalars, Vectors, Matrices, and Tensors
Deep learning uses arrays of numbers. The first difference between arrays is the number of axes they have.
A scalar is one number.
7
A vector is a one-axis array.
[2, -1, 5]
A matrix is a two-axis array.
[
[2, -1, 5],
[0, 3, 4]
]
A tensor is the general word for an array with axes. In practice, people often use tensor for any array in a deep learning system, even a scalar, vector, or matrix.
The important question is not “is this a tensor?” The important question is “what do the axes mean?”
Shapes
Shape records the size of each axis.
[2, -1, 5] shape: (3)
[
[2, -1, 5],
[0, 3, 4]
] shape: (2, 3)
The first shape says: one axis with 3 entries.
The second shape says: 2 rows and 3 columns.
In deep learning, shape is not bookkeeping after the real work. Shape is part of the real work. It tells you what can connect to what.
A vector has 6 entries. What is its shape size?
Compute it first, then check your number.
HintThink about axes
A vector has one axis. Count the entries along that axis.
SolutionWork it out
The vector has one axis and 6 entries along that axis, so its shape is
(6). The numerical size to enter is 6.
The array below has 3 rows and 2 columns.
[
[1, 4],
[2, 5],
[3, 6]
]
Enter 1 for scalar, 2 for vector, 3 for matrix, or 4 for a three-axis tensor.
Compute it first, then check your number.
HintCount axes
Rows and columns are two axes.
SolutionWork it out
The array has a row axis and a column axis. That makes it a matrix, so the
correct code is 3.