B.1. Tensor creation and tensor axis conventions

Remember that a tensor is simply a data container. Every tensor has two fundamental properties: data type (dtype) and shape. dtype controls what kinds of values are stored within the tensor. A given tensor can store only one kind of value. At the time of this writing (version 0.13.5), the supported dtypes are float32, int32, and bool.

The shape is an array of integers indicating how many elements are in the tensor and how they are organized. It can be thought of as the “shape and size” of the container that is the tensor (see figure B.1).

Figure B.1. Examples of tensors of rank 0, 1, 2, 3, and 4

The length of the shape is known as the tensor’s rank. For example, a 1D tensor, also known as ...

Get Deep Learning with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.