1. 程式人生 > >5.什麽是tensor(下)

5.什麽是tensor(下)

bubuko 技術分享 port flow highlight 什麽是 div imp light

import tensorflow as tf

# tensorflow還支持變量的定義
var = tf.Variable(3)
print(var)  # <tf.Variable ‘Variable:0‘ shape=() dtype=int32_ref>

# 也可以指定類型和名字
var1 = tf.Variable(4, name="mmp", dtype=tf.float64)
print(var1)  # <tf.Variable ‘mmp:0‘ shape=() dtype=float64_ref>

# 關於參數shape,表示變量是幾維的
var2 = tf.Variable([1, 2, 3])
print(var2)  # <tf.Variable ‘Variable_1:0‘ shape=(3,) dtype=int32_ref>

var3 = tf.Variable([[1, 2, 3], [4, 5, 6]])
print(var3)  # <tf.Variable ‘Variable_2:0‘ shape=(2, 3) dtype=int32_ref>

  技術分享圖片

5.什麽是tensor(下)