書(shū)名: TensorFlow Machine Learning Projects作者名: Ankit Jain Armando Fandango Amita Kapoor本章字?jǐn)?shù): 236字更新時(shí)間: 2021-06-10 19:15:27
Constants
The constant valued tensors are created using the tf.constant() function, and has the following definition:
tf.constant(
value,
dtype=None,
shape=None,
name='const_name',
verify_shape=False
)
Let's create some constants with the following code:
const1=tf.constant(34,name='x1')
const2=tf.constant(59.0,name='y1')
const3=tf.constant(32.0,dtype=tf.float16,name='z1')
Let's take a look at the preceding code in detail:
- The first line of code defines a constant tensor, const1, stores a value of 34, and names it x1.
- The second line of code defines a constant tensor, const2, stores a value of 59.0, and names it y1.
- The third line of code defines the data type as tf.float16 for const3. Use the dtype parameter or place the data type as the second argument to denote the data type.
Let's print the constants const1, const2, and const3:
print('const1 (x): ',const1)
print('const2 (y): ',const2)
print('const3 (z): ',const3)
When we print these constants, we get the following output:
const1 (x): Tensor("x:0", shape=(), dtype=int32)
const2 (y): Tensor("y:0", shape=(), dtype=float32)
const3 (z): Tensor("z:0", shape=(), dtype=float16)
Upon printing the previously defined tensors, we can see that the data types of const1 and const2 are automatically deduced by TensorFlow.
To print the values of these constants, we can execute them in a TensorFlow session with the tfs.run() command:
print('run([const1,const2,c3]) : ',tfs.run([const1,const2,const3]))
We will see the following output:
run([const1,const2,const3]) : [34, 59.0, 32.0]
推薦閱讀
- 電力自動(dòng)化實(shí)用技術(shù)問(wèn)答
- 大數(shù)據(jù)改變世界
- 自動(dòng)檢測(cè)與轉(zhuǎn)換技術(shù)
- Mastering Elastic Stack
- 大數(shù)據(jù)安全與隱私保護(hù)
- 工業(yè)機(jī)器人維護(hù)與保養(yǎng)
- 自動(dòng)化生產(chǎn)線(xiàn)安裝與調(diào)試(三菱FX系列)(第二版)
- Mastering Ceph
- 新一代人工智能與語(yǔ)音識(shí)別
- 自適應(yīng)學(xué)習(xí):人工智能時(shí)代的教育革命
- 數(shù)據(jù)清洗
- Advanced Deep Learning with Keras
- 網(wǎng)絡(luò)信息安全項(xiàng)目教程
- 基于元胞自動(dòng)機(jī)的人群疏散系統(tǒng)建模與分析
- 工業(yè)控制系統(tǒng)安全