TensorFlow programs use a tensor data structure to represent all data. You can think of a TensorFlow tensor as an n-dimensional array or list. A tensor has a static type and dynamic dimensions. Only tensors may be passed between nodes in the computation graph.
In the TensorFlow system, tensors are described by a unit of dimensionality known as rank. Tensor rank is not the same as matrix rank. Tensor rank (sometimes referred to as order or degree or n-dimension) is the number of dimensions of the tensor. For example, the following tensor (defined as a Python list) has a rank of 2:
t = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
A rank two tensor is what we typically think of as a matrix, a rank one tensor is a vector. For a rank two tensor you can access any element with the syntax
t[i, j]. For a rank three tensor you would need to address an element with
t[i, j, k].
|Rank||Math entity||Python example|
|0||Scalar (magnitude only)|| |
|1||Vector (magnitude and direction)|| |
|2||Matrix (table of numbers)|| |
|3||3-Tensor (cube of numbers)|| |
|n||n-Tensor (you get the idea)|| |
The TensorFlow documentation uses three notational conventions to describe tensor dimensionality: rank, shape, and dimension number. The following table shows how these relate to one another:
|0||||0-D||A 0-D tensor. A scalar.|
|1||[D0]||1-D||A 1-D tensor with shape .|
|2||[D0, D1]||2-D||A 2-D tensor with shape [3, 4].|
|3||[D0, D1, D2]||3-D||A 3-D tensor with shape [1, 4, 3].|
|n||[D0, D1, ... Dn-1]||n-D||A tensor with shape [D0, D1, ... Dn-1].|
Shapes can be represented via Python lists / tuples of ints, or with the
In addition to dimensionality, Tensors have a data type. You can assign any one of the following data types to a tensor:
|Data type||Python type||Description|
| || ||32 bits floating point.|
| || ||64 bits floating point.|
| || ||8 bits signed integer.|
| || ||16 bits signed integer.|
| || ||32 bits signed integer.|
| || ||64 bits signed integer.|
| || ||8 bits unsigned integer.|
| || ||16 bits unsigned integer.|
| || ||Variable length byte arrays. Each element of a Tensor is a byte array.|
| || ||Boolean.|
| || ||Complex number made of two 32 bits floating points: real and imaginary parts.|
| || ||Complex number made of two 64 bits floating points: real and imaginary parts.|
| || ||8 bits signed integer used in quantized Ops.|
| || ||32 bits signed integer used in quantized Ops.|
| || ||8 bits unsigned integer used in quantized Ops.|
© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.