tensor tensor i.e., tf is the core data structure, which may be a scalar, vector, matrix, multi-dimensional arrays
Attributes
Data Format
tf.string, tf.float32, tf.int16, tf.int32, tf.complex64 (complex), tf.bool like
Shape data
1. The shape is a shape Tensor properties may be obtained directly, without session
2. The shape is not necessarily determined at compile time, it can be inferred by running
Order: Tensor dimension
Of the order of acquisition requires session
Examples
tf.ones = D1 ([. 3, 2 ]) Print (d1.shape) # (. 3, 2) Shape may be obtained directly, without the session N1 = tf.rank (D1) Print (N1) # the Tensor ( "Rank: 0 ", shape = (), dtype = int32) not directly acquire the order requires the session D2 = tf.constant ([[[. 1,. 1,. 1], [2, 2, 2]], [[. 3,. 3, . 3], [. 4,. 4,. 4 ]]]) Print (D2) # the Tensor ( "Const: 0", Shape = (2, 2,. 3), DTYPE = Int32) N2 = tf.rank (D2) with TF the .session () AS sess: Print (sess.run (N1)) # 2 tensor Print (sess.run (n2)) # 3 rank tensor
tf There are several more special tensor
tf.constant constant
tf.Variable variable
tf.placeholder placeholder
constant
Note that:
1. The different types of operation is not constant
2. constant variables like the python as a direct assignment
def constant(value, dtype=None, shape=None, name="Const")
Examples
# ## single element D1 tf.constant = (. 1 ) D2 = tf.constant (2, DTYPE = tf.int32, name = ' int ' ) D3 = tf.constant (. 3., DTYPE = tf.float32, name = ' a float ' ) D4 = tf.add (D1, D2) # d5 of D1 + D3 = ### different types of operational data can not d6 = D1 + D2 sess1 = tf.Session () Print (sess1.run (D4)) # 3 # Print (sess1.run (D5)) ### float32 does not match error of the type of the type Int32 Print (sess1.run (d6)) # 3 Print(type(d6)) # <class 'tensorflow.python.framework.ops.Tensor'> ### 矩阵 d1 = tf.constant([[1., 2.]]) d2 = tf.constant([[2.], [3.]]) d3 = tf.matmul(d1, d2) ## 常数赋值 d2 = d1 sess2 = tf.Session() print(sess2.run(d3)) # [[8.]] print(sess2.run(d2)) # [[1. 2.]]
References: