码迷,mamicode.com
首页 > 其他好文 > 详细

TensorFlow基本计算单元——变量

时间:2017-12-31 20:57:10      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:ini   var   col   向量   type   run   ble   创建   全局   

# -*- 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基本计算单元——变量

标签:ini   var   col   向量   type   run   ble   创建   全局   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!