07 Constant 資料型態

Constant 可以存放多樣式的資料型態,常見的資料型態有:
• tf.float16: 16-bit 半精度浮點。
• tf.float32: 32-bit 單精度浮點。
• tf.float64:64位雙精度浮點。
• tf.bfloat16:16位截斷浮點。
• tf.complex64:64位單精度複合體。
• tf.complex128:128位雙精度複合體。
• tf.int8:8位有符號整數。
• tf.uint8:8位無符號整數。
• tf.uint16:16位無符號整數。
• tf.int16:16位有符號整數。
• tf.int32:32位有符號整數。
• tf.int64:64位有符號整數。
• tf.bool:布林代數。
• tf.string:字符串。
• tf.qint8:量化的8位有符號整數。
• tf.quint8:量化的8位無符號整數。
• tf.qint16:量化的16位有符號整數。
• tf.quint16:量化的16位無符號整數。
• tf.qint32:量化的32位有符號整數。
• tf.resource:處理可變資源。
• tf.variant:任意類型的值。

範例程式06_string.py
1. import tensorflow as tf
2. node1 = tf.constant(“Hello”)
3. node2 = tf.constant(” www.PowenKo.com”)
4. print(node1, node2)
5. sess = tf.Session()
6. print(sess.run(node1+node2))

輸出為
(<tf.Tensor ‘Const:0’ shape=() dtype=string>, <tf.Tensor ‘Const_1:0’ shape=() dtype=string>)
2018-01-16 21:01:30.890335: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
Hello www.PowenKo.com

 

 

圖6 執行結果