Order, shape, data type of tensor
TensorFlow uses this data structure to represent all of the information. You can think of a tensor as an n-dimensional array or list. A tensor has a static type and a dynamic type of dimension. Tensor can flow between nodes in the diagram. Order
In the TensorFlow system, The dimensions of the tensor are described as orders. But the order of the tensor and the order of the matrices are not the same concept. The Order of the tensor (sometimes about, for example, order or degree or n-dimensional) is a quantity description of the number of Zhang Xiwei. For example, the following tensor (defined in Python list) is a 2-order.
t = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
You can think of a second-order tensor, which is what we normally call a matrix, the first order tensor can be thought of as a vector. For a second order tensor you can use the statement t[i, J] to access any of these elements. And for the third-order tensor you can use ' T[i, J, K ' to access any of these elements. Order Math Example Python example 0 scalar (only size) s = 483 1 vectors (size and direction) v = [1.1, 2.2, 3.3] 2 matrix (data table) m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 3 3 order Sheets Quantity (data stereo) T = [[2], [4], [6]], [[8], [ten], [a]], [[[], [], []]] n n order (think for yourself) .... Shape
The TensorFlow document uses three tokens to easily describe the dimensions of the tensor: order, shape, and dimension. The following table shows the relationship between them: the Order Shape dimension instance 0 [] 0-d a 0-dimensional tensor. A pure quantity. 1 [D0] 1-d the form of a 1-dimensional tensor [5]. 2 [D0, D1] 2-d the form of a 2-dimensional tensor [3, 4]. 3 [D0, D1, D2] The form of a 3-dimensional tensor [1, 4, 3]. n [D0, D1, ... Dn] n-d The form of an n-dimensional tensor [D0, D1, ... Dn]. Shape [2,3] means that the array means that the first dimension has two elements, and the second dimension has three elements, such as: [[1,2,3],[4,5,6]]
' Python # 2-d tensor ' a ' a = Tf.constant ([1, 2, 3, 4, 5, 6], shape=[2, 3]) => [[1].
2.3.] [4.5. 6.]] # 2-d tensor ' b ' B = tf.constant ([7, 8, 9, ten, one, one], shape=[3, 2]) => [[7]. 8.] [9. 10.] [11. A.]] C = Tf.matmul (A, b) => [[139 154]] # The tensor ' a ' a = Tf.constant (NP. Arange (1,13), Shape=[2, 2, 3]) => [[[1].
2.3.] [4.5. 6.]], [[7].
8.9.] [10.11. []]] # tensor ' b ' B = tf.constant (Np.arange (13,25), Shape=[2, 3, 2]) => [[[13]. 14.] [15. 16.] [17.18.]], [[19. 20.] [21. 22.] [23.
]]] C = Tf.matmul (A, b) => [[[94 100] [229 244]], [[508 532] [697 730]]]
In TensorFlow, there is a class of functions that are evaluated on a dimension of tensor,
Such as:
Max value Tf.reduce_max (Input_tensor, Reduction_indices=none, Keep_dims=false, Name=none)
Average Tf.reduce_mean (Input_tensor, Reduction_indices=none, Keep_dims=false, Name=none)
Parameter (1) Input_tensor: tensor of the value to be evaluated.
Parameter (2) Reduction_indices: On which dimension to solve.
Parameter (3) (4) can be ignored
An example is provided:
# ' x ' is [[1., 2.]
# [3., 4.]]
X is a 2-D array that calls the Reduce_* function, respectively, as follows:
First, the average,
Tf.reduce_mean (x) ==> 2.5 #如果不指定第二个参数, the average of all elements is
Tf.reduce_mean (x, 0) ==> [2., 3.] #指定第二个参数为0, The elements of the first dimension are averaged, that is, each column is averaged
tf.reduce_mean (x, 1) ==> [1., 2.] #指定第二个参数为1, then the elements of the second dimension are averaged, that is, each row is averaged
Similarly, you can also use Tf.reduce_max () to find the maximum value.