In this chapter, we will learn about the basics of TensorFlow. We will first understand the data structure of tensors.
Tensor Data Structure
Tensors are used as the basic data structure in the TensorFlow language. Tensors represent connected edges in a flow graph, called a data flow graph. Tensors are defined as multidimensional arrays or lists.
Tensors are identified by the following three parameters −
1. Rank
The unit describing the dimension within the tensor is called rank. It identifies the number of dimensions of the tensor. The rank of a tensor can be described as the order or n-dimension of the tensor.
2. Shape
The number of rows and columns together defines the shape of the tensor.
3. Type
The type describes the data type assigned to the tensor elements.
The user needs to consider the following activities to build a tensor −
1. Construct an n-dimensional array
2. Convert the n-dimensional array.
TensorFlow includes various dimensions. These dimensions are briefly described below −
One-dimensional tensor
A one-dimensional tensor is an ordinary array structure that contains a set of values of the same data type.
statement
>>> import numpy as np
>>> tensor_1d = np.array([1.3, 1, 4.0, 23.99])
>>> print tensor_1d
Following is the implementation with output as shown in the image below −
element's string