TensorFlow基本计算单元——变量

# -*- 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.]]

 

posted @ 2017-12-31 17:08  黎明程序员  阅读(273)  评论(0编辑  收藏  举报