Tensors and basic operations on tensors
A tensor is a basic data structure in tfjs
. You can think of tensors as a generalization of vectors, matrices, or high-dimensional arrays. The CoreAPI, which we introduced in the What is TensorFlow.js? section, exposes different functions for creating and working with tensors.
The following screenshot shows a simple comparison between scalars, vectors, and a matrix with a tensor:
Tip
A matrix is a grid of m x n
numbers, where m
represents the number of rows and n
represents the number of columns. A matrix can be of one or more dimensions, and matrixes of the same shape support direct mathematical operations on each other.
A vector, on the other hand, is a one-dimensional matrix with shape (1, 1); that is, it has a single row and column—for example, [2, 3], [3, 1, 4].
We mentioned earlier that a tensor is more of a generalized...