# -*- coding: utf-8 -*- import tensorflow as tf a = 3 # 創建變量 w = tf.Variable([[0.5, 1.0]]) #行向量 x = tf.Variable([[2.0], [1.0]]) y = tf.matmul(w, x) #矩陣相乘 print(y) # Tensor("MatMul:0", shape=(1, 1), dtype=float32) init_op = tf.global_variables_initializer() #獲取初始化全局變量的對象 with tf.Session() as sess: #初始化要在會話中進行sess.run(init_op) #初始化變量print (y.eval()) #打印y的值 # [[ 2.]]
?