首页 > 其他 > 详细

TensorFlow基本计算单元——变量

时间:2017-12-31 20:44:05      阅读:193      评论:0      收藏:0      [点我收藏+]
# -*- 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.]]

 

TensorFlow基本计算单元——变量

原文:https://www.cnblogs.com/itmorn/p/8158135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!